【问题标题】:AttributeError: 'Command' object has no attribute 'check'AttributeError:“命令”对象没有属性“检查”
【发布时间】:2025-12-22 23:55:06
【问题描述】:
def user_is_me(ctx):
    return ctx.message.author.id == "310426385090871296"

@FiveStarBot.command(pass_context=True)
@commands.check(user_is_me)
async def message(cxt, member: discord.Member, *, text : str):
    print('\n[Лог использования команды !message]')
    print('Отправитель: ', cxt.message.author, ' Получатель: ', member, ' Текст: ', text)
    await FiveStarBot.send_message(member, text)

新错误。 W/o @commands.check(user_is_me) 一切正常

【问题讨论】:

  • 请将错误堆栈跟踪放在帖子本身
  • 另外,发布更多代码。此处的代码无法识别问题。

标签: python discord.py


【解决方案1】:

您需要使用pass_context=True 参数到bot.command 以传递上下文。

@bot.command(pass_context=True)
@commands.check(user_is_me)
async def hello(cxt):
   await bot.say('Hello')

【讨论】:

  • 我收到新命令的新错误。 @FiveStarBot.command(pass_context=True) @commands.check(user_is_me) async def message(cxt, member: discord.Member, *, text : str): print('\n[Лог использования команды !message]') print ('Отправитель: ', cxt.message.author, ' Получатель: ', member, ' Текст: ', text) await FiveStarBot.send_message(member, text) 错误:AttributeError: 'Command' 对象没有属性 'check'
  • @RomanMystery 你有一个名为commands 的命令吗?停止重复使用名称。如果必须,可以将协程命名为commands_,然后将name="commands" 传递给bot.command
  • 这么多愚蠢的错误。是的,我已经有一个“命令”命令。再次感谢您帮助我。
最近更新 更多