application_checks error
Summary
application_checks.check_any() raises a TypeError
Reproduction Steps
Wrap a slash command in application_checks.check_any() decorator with has_permissions() or has_guild_permissions() checks.
Minimal Reproducible Code
import nextcord
from nextcord.ext import commands, application_checks
bot = commands.Bot(intents=nextcord.Intents.all())
class TestCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot: commands.Bot = bot
@nextcord.slash_command()
@application_checks.check_any(
application_checks.has_permissions(administrator=True)
)
async def test(self, interaction: nextcord.Interaction):
await interaction.send('Hello World')
bot.add_cog(TestCog(bot))
bot.run('TOKEN')
Expected Results
The slash command registers without any errors.
Actual Results
Traceback (most recent call last):
File "d:\gradientbot\tests\test.py", line 17, in <module>
class TestCog(commands.Cog):
File "d:\gradientbot\tests\test.py", line 22, in TestCog
@application_checks.check_any(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "d:\gradientbot\venv\Lib\site-packages\nextcord\ext\application_checks\core.py", line 223, in check_any
raise TypeError(
TypeError: <function _permission_check_wrapper.<locals>.wrapper at 0x000001DE62F423E0> must be wrapped by application_checks.check decorator
Intents
nextcord.Intents.all()
System Information
- Python v3.11.5-final
- nextcord v2.6.0-final
- aiohttp v3.9.1
- system info: Windows 10 10.0.19045
Checklist
- [x] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.
Additional Context
The problem seems to occur only with these checks:
-
has_permissions -
has_guild_permissions -
bot_has_permissions -
bot_has_guild_permissions
This decorator works fine:
@application_checks.check_any(
application_checks.is_owner(),
)
Same happens with nextcord.ext.commands.check_any() and nextcord.ext.commands.has_guild_permissions(). Most likely, the issue affects every permission check.
- Code:
import nextcord
from nextcord.ext import commands
client = commands.Bot("test!", intents=nextcord.Intents.all())
@client.command()
@commands.check_any(commands.has_guild_permissions(manage_guild=True))
async def ping(ctx: commands.Context):
return await ctx.send("Pong!")
client.run("TOKEN")
- Traceback:
Traceback (most recent call last):
File "c:\path\to\bot\main.py", line 8, in <module>
@commands.check_any(commands.has_guild_permissions(manage_guild=True))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\path\to\bot\.venv\Lib\site-packages\nextcord\ext\commands\core.py", line 1929, in check_any
raise TypeError(f"{wrapped!r} must be wrapped by commands.check decorator") from None
TypeError: <function _permission_check_wrapper.<locals>.wrapper at 0x0000026C5B01D800> must be wrapped by commands.check decorator
- System info: Python 3.11.8, Nextcord-3.0.0a25+g1c860268, aiohttp 3.9.3, Windows 11 22631.3155.
This is not the same @A1Asriel, that is ext.commands.
This is not the same @A1Asriel, that is
ext.commands.
I understand, but even if it's in another module, it still produces the same error and is triggered by the same conditions. I can open another issue, if needed.
Has anyone found a workaround to this issue? I tried to fix the bug myself but quickly gave up..
@Lenochxd you can copy the original check function and change the return statement to return application_checks.check(predicate). Example:
def has_permissions(**perms):
invalid = set(perms) - set(nextcord.Permissions.VALID_FLAGS)
if invalid:
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
def predicate(interaction: nextcord.Interaction) -> bool:
ch = interaction.channel
try:
permissions = ch.permissions_for(interaction.user)
except AttributeError:
raise application_checks.ApplicationNoPrivateMessage()
missing = [perm for perm, value in perms.items() if getattr(permissions, perm) != value]
if not missing:
return True
raise application_checks.ApplicationMissingPermissions(missing)
return application_checks.check(predicate)
Then use it as usual:
@application_checks.check_any(
has_permissions(administrator=True)
)