async def set_rules_react_message_id(self, ctx, message_id: int): """ Set the message ID of the rules react-to-join message Setting rules message ID also clears reactions, and may be helpful if discord glitches from too many reacts message_id: Message id of rules react message """ rules_channel = self.bot.get_config_channel(ctx.guild.id, Utils.rules_channel) if message_id and not rules_channel: ctx.send( 'Rules channel must be set in order to set rules message. Try `!channel_config set rules_channel [id]`' ) # clear old reactions rules_message_id = Configuration.get_var('rules_react_message_id') try: # Un-setting rules message. Clear reactions from the old one. old_rules = await rules_channel.fetch_message(rules_message_id) await old_rules.clear_reactions() await ctx.send(f"Cleared reactions from:\n{old_rules.jump_url}") # TODO: make this guild-specific except Exception as e: await ctx.send(f"Failed to clear existing rules reactions") try: Configuration.MASTER_CONFIG['rules_react_message_id'] = message_id Configuration.save() except Exception as e: await ctx.send( f"Failed while saving configuration. Operation will continue, but check the logs..." ) if message_id == 0: if rules_message_id == 0: await ctx.send(f"Rules message is already unset") return try: new_rules = await rules_channel.fetch_message(message_id) roles = Configuration.get_var("roles") await new_rules.clear_reactions() for emoji, role_id in roles.items(): # if not Emoji.is_emoji_defined(emoji): # continue # emoji = Emoji.get_chat_emoji(emoji) await new_rules.add_reaction(emoji) await ctx.send( f"Rules message set to {message_id} in channel {rules_channel.mention}" ) except (discord.NotFound, discord.Forbidden, discord.HTTPException) as e: await ctx.send( f"Could not find message id {message_id} in channel {rules_channel.mention}" )
async def unload(self, ctx, cog: str): if cog in ctx.bot.cogs: self.bot.unload_extension(f"cogs.{cog}") if cog in Configuration.MASTER_CONFIG["cogs"]: Configuration.get_var("cogs").remove(cog) Configuration.save() await ctx.send(f'**{cog}** has been unloaded.') await Logging.bot_log( f'**{cog}** has been unloaded by {ctx.author.name}') Logging.info(f"{cog} has been unloaded") else: await ctx.send( f"{Emoji.get_chat_emoji('NO')} I can't find that cog.")
async def load(self, ctx, cog: str): if os.path.isfile(f"cogs/{cog}.py"): self.bot.load_extension(f"cogs.{cog}") if cog not in Configuration.MASTER_CONFIG["cogs"]: Configuration.MASTER_CONFIG["cogs"].append(cog) Configuration.save() await ctx.send(f"**{cog}** has been loaded!") await Logging.bot_log( f"**{cog}** has been loaded by {ctx.author.name}.") Logging.info(f"{cog} has been loaded") else: await ctx.send( f"{Emoji.get_chat_emoji('NO')} I can't find that cog.")