Cog check not run for app commands. #9161
Answered
by
Rapptz
sam-hudson02
asked this question in
Q&A
-
class ModCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.ac: AudioController = bot.ac
self.settings: Settings = bot.settings
self.log: Log = bot.log
self.db = bot.db
async def cog_check(self, ctx) -> bool:
roles = [role.name for role in ctx.author.roles]
if not 'DJ' in roles:
raise NotAuthorized
return True
async def cog_app_command_error(self, ctx, error) -> None:
error = getattr(error, 'original', error)
if isinstance(error, NotAuthorized):
resp = f'Sorry, you need the role "DJ" to use this command.'
else:
resp = f'An unknown error occurred'
await ctx.response.send_message(content=resp, ephemeral=True)
self.log.resp(resp)
self.log.error(error)
@discord.app_commands.command(name='skip', description='Skip the current song')
@discord.app_commands.check(cog_check)
async def skip(self, ctx):
if self.settings.active and self.ac.context.live:
await self.ac.play_next(skipped=True)
resp = f'Skipping current track!'
else:
resp = 'Nothing to skip!'
await ctx.response.send_message(content=resp, ephemeral=True)
self.log.resp(resp) Is there anyway to do a cog check or before invoke method before an app command? I've tried using the app_commands.check() decorator but it seems to break the command and I'd ideally like to run the check for every command in the cog without adding a decorator. |
Beta Was this translation helpful? Give feedback.
Answered by
Rapptz
Jan 1, 2023
Replies: 1 comment
-
Cog checks are for regular commands not for app commands so they don't get used for those. There is currently no cog app command check system in place right now similar to |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sam-hudson02
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cog checks are for regular commands not for app commands so they don't get used for those. There is currently no cog app command check system in place right now similar to
cog_check
.