如何修复 discordpy 中的命令检查错误?
How do I fix commands check error in discordpy?
所以我的检查似乎没有用,我相信功能设置正确但我可能错了我应该如何解决这个错误?
@client.command()
@commands.check(is_server_owner)
async def serversetup(guild,ctx):
await guild.create_role(name='safe')
await ctx.send('Please put the safe role above the AntiNuke role so those people will not be punished by the antinuke! | Server is setup!')
这是我遇到的错误
Ignoring exception in command serversetup:
Traceback (most recent call last):
File "/home/runner/AntiNuke/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/AntiNuke/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 855, in invoke
await self.prepare(ctx)
File "/home/runner/AntiNuke/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 778, in prepare
raise CheckFailure('The check functions for command {0.qualified_name} failed.'.format(self))
discord.ext.commands.errors.CheckFailure: The check functions for command serversetup failed.
这里是is_server_owner函数
def is_server_owner(ctx):
return ctx.message.author.id == ctx.guild.owner
问题是在你的check
中你会检查作者的id
是否与公会所有者的对象相同,所以它总是return false
。要解决此问题,只需将 ctx.message.author.id
更改为 ctx.message.author
。
所以我的检查似乎没有用,我相信功能设置正确但我可能错了我应该如何解决这个错误?
@client.command()
@commands.check(is_server_owner)
async def serversetup(guild,ctx):
await guild.create_role(name='safe')
await ctx.send('Please put the safe role above the AntiNuke role so those people will not be punished by the antinuke! | Server is setup!')
这是我遇到的错误
Ignoring exception in command serversetup:
Traceback (most recent call last):
File "/home/runner/AntiNuke/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/AntiNuke/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 855, in invoke
await self.prepare(ctx)
File "/home/runner/AntiNuke/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 778, in prepare
raise CheckFailure('The check functions for command {0.qualified_name} failed.'.format(self))
discord.ext.commands.errors.CheckFailure: The check functions for command serversetup failed.
这里是is_server_owner函数
def is_server_owner(ctx):
return ctx.message.author.id == ctx.guild.owner
问题是在你的check
中你会检查作者的id
是否与公会所有者的对象相同,所以它总是return false
。要解决此问题,只需将 ctx.message.author.id
更改为 ctx.message.author
。