Build invite link only once + fixed slash_command loading

This commit is contained in:
2021-10-31 11:23:17 +01:00
parent 9338f0a3c3
commit 1c51e6a4bc
+13 -8
View File
@@ -31,16 +31,24 @@ class ChristmasBot(commands.Bot):
self.config = config self.config = config
self.colors: Dict[str, Color] = self.process_colours(config.get("colors", [])) self.colors: Dict[str, Color] = self.process_colours(config.get("colors", []))
self.invite_link: str = ""
super().__init__( super().__init__(
command_prefix=self.prefix_callable, command_prefix=self.prefix_callable,
description=self.config["info"].get("description"), description=self.config["info"].get("description", ""),
case_insensitive=False, case_insensitive=False,
fetch_offline_members=False, fetch_offline_members=False,
intents=intents, intents=intents,
slash_commands=True,
slash_command_guilds=[227431704426446848], slash_command_guilds=[227431704426446848],
) )
async def prefix_callable(self, _, msg: Message): self.loop.create_task(self.async_init())
async def async_init(self):
await self.load_cogs(self.initial_cog_names)
async def prefix_callable(self, _, msg: Message) -> List[str]:
return commands.when_mentioned_or(*self.config["prefixes"])(self, msg) return commands.when_mentioned_or(*self.config["prefixes"])(self, msg)
async def load_cogs(self, cog_names: Sequence[str]): async def load_cogs(self, cog_names: Sequence[str]):
@@ -52,14 +60,11 @@ class ChristmasBot(commands.Bot):
print(f"Failed to load extension {cog}.\n\t{e}", file=sys.stderr) print(f"Failed to load extension {cog}.\n\t{e}", file=sys.stderr)
async def on_ready(self): async def on_ready(self):
self.invite_link = f"https://discord.com/oauth2/authorize?client_id={self.user.id}&permissions=3230720&scope=bot%20applications.commands"
print(f"Logged in as: {self.user}") print(f"Logged in as: {self.user}")
print(f"Version: {discord.__version__}") print(f"Version: {discord.__version__}")
print( print(f"Invite: {self.invite_link}")
f"Invite: https://discord.com/oauth2/authorize?scope=bot&client_id=257816631072391168&permissions=70642768"
)
text = "ck!connect | ck!help"
await self.change_presence(activity=discord.Game(text))
await self.load_cogs(self.INITIAL_EXTENSIONS)
def process_colours(self, colors: Dict[str, str]) -> Dict[str, Color]: def process_colours(self, colors: Dict[str, str]) -> Dict[str, Color]:
colour_dict: Dict[str, Color] = {} colour_dict: Dict[str, Color] = {}