-
i have a bot running, which is my main. to test another bot, i run another bot with the same bot token. i had old slash commands and new commands bot. that is fine. import discord, os
from discord.ext import commands
extensions = (
"cogs.admin_msg",
"cogs.memes",
"cogs.events",
)
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
class MYBOT(commands.Bot):
def __init__(self):
super().__init__(
command_prefix="sudo ",
intents=intents,
)
async def setup_hook(self):
for extension in extensions:
await self.load_extension(extension)
await bot.tree.sync(guild = discord.Object(id=my guild id goes here))
bot = MYBOT()
@bot.check
async def globally_block_dms(ctx):
return ctx.guild is not None
bot.run(token)
reconnect=True the another bot which is not running anymore was like this: imports ...
initial_extensions = ['cogs.admin', 'cogs.errors', 'cogs.notify', 'cogs.valorant']
# intents
class ValorantBot(commands.Bot):
debug: bool
bot_app_info: discord.AppInfo
def __init__(self) -> None:
super().__init__(command_prefix=BOT_PREFIX, case_insensitive=True, intents=intents)
self.session: aiohttp.ClientSession = None
self.bot_version = '3.3.5'
self.tree.interaction_check = self.interaction_check
@staticmethod
async def interaction_check(interaction: discord.Interaction) -> bool:
locale_v2.set_interaction_locale(interaction.locale) # bot responses localized # wait for update
locale_v2.set_valorant_locale(interaction.locale) # valorant localized
return True
@property
def owner(self) -> discord.User:
return self.bot_app_info.owner
async def on_ready(self) -> None:
await self.tree.sync()
print(f"\nLogged in as: {self.user}\n\n BOT IS READY !")
print(f"Version: {self.bot_version}")
# bot presence
activity_type = discord.ActivityType.listening
await self.change_presence(activity=discord.Activity(type=activity_type, name="(╯•﹏•╰)"))
async def setup_hook(self) -> None:
if self.session is None:
self.session = aiohttp.ClientSession()
try:
self.owner_id = int(os.getenv('OWNER_ID'))
except ValueError:
self.bot_app_info = await self.application_info()
self.owner_id = self.bot_app_info.owner.id
self.setup_cache()
await self.load_cogs()
async def load_cogs(self) -> None:
for ext in initial_extensions:
try:
await self.load_extension(ext)
except (
ExtensionNotFound,
NoEntryPointError,
ExtensionFailed,
):
print(f'Failed to load extension {ext}.', file=sys.stderr)
traceback.print_exc()
@staticmethod
def setup_cache() -> None:
try:
open('data/cache.json')
except FileNotFoundError:
get_cache()
async def close(self) -> None:
await self.session.close()
await super().close()
async def start(self, debug: bool = False) -> None:
self.debug = debug
return await super().start(os.getenv('TOKEN'), reconnect=True)
def run_bot() -> None:
bot = ValorantBot()
asyncio.run(bot.start())
if __name__ == '__main__':
run_bot() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
This might be because your other code added them as global commands which stay when re-adding an application. The code shown here would only remove guild commands that no longer exist. |
Beta Was this translation helpful? Give feedback.
This might be because your other code added them as global commands which stay when re-adding an application. The code shown here would only remove guild commands that no longer exist.