【问题标题】:How do I fix commands check error in discordpy?如何修复 discordpy 中的命令检查错误?
【发布时间】:2022-02-23 13:58:59
【问题描述】:

看来我的检查不起作用,我相信功能设置正确但我可能错了我应该如何解决这个错误?

@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

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

问题是在你的check中你检查作者的id是否和公会老板的对象一样,所以它总是会返回false。要解决此问题,只需将 ctx.message.author.id 更改为 ctx.message.author

【讨论】:

  • 或将ctx.guild.owner改为ctx.guild.owner_id
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-21
  • 1970-01-01
  • 2018-05-01
  • 2020-10-24
  • 2021-03-24
  • 1970-01-01
  • 2021-10-14
相关资源
最近更新 更多