import discord from discord import app_commands MOD_LOG = "mod_log_channel" MOD_ROLE = "mod_role" ADMIN_ROLE = "admin_role" VERIFIED_ROLE = "verified_role" VERIFY_CHANNEL = "verify_channel" VERIFY_REVIEW = "verify_review_channel" VERIFY_ENABLED = "verify_enabled" VERIFY_RULES_MSG = "verify_rules_message" JOIN_CHANNEL = "join_applications_channel" async def get_id(bot, key): value = await bot.db.get_setting(key) return int(value) if value else None async def mod_log_channel(bot, guild): channel_id = await get_id(bot, MOD_LOG) return guild.get_channel(channel_id) if channel_id else None async def send_mod_log(bot, guild, **kwargs): """Send to the mod-log channel. Returns the message, or None if unavailable.""" channel = await mod_log_channel(bot, guild) if channel is None: return None try: return await channel.send(**kwargs) except discord.HTTPException: return None async def is_admin(bot, member): if member.guild_permissions.administrator: return True admin_role = await get_id(bot, ADMIN_ROLE) return admin_role is not None and any(r.id == admin_role for r in member.roles) async def is_mod(bot, member): if await is_admin(bot, member): return True mod_role = await get_id(bot, MOD_ROLE) return mod_role is not None and any(r.id == mod_role for r in member.roles) def mod_only(): async def predicate(interaction): if await is_mod(interaction.client, interaction.user): return True raise app_commands.CheckFailure("You need to be a moderator to use this.") return app_commands.check(predicate) def admin_only(): async def predicate(interaction): if await is_admin(interaction.client, interaction.user): return True raise app_commands.CheckFailure("You need to be an admin to use this.") return app_commands.check(predicate)