代码之家  ›  专栏  ›  技术社区  ›  Mooles

函数“say”抛出attributeError:'str'对象没有属性'channel'错误

  •  0
  • Mooles  · 技术社区  · 7 年前

    我正在使用 @bot.command() 但是,我的 !say 命令不会接受用户的输入然后让bot说出来

    @bot.command()
    async def say(message):
      #await bot.delete_message(message)
      await bot.send_message(message.channel, message)
    

    这是一个discord服务器,bot为我自动管理东西,并提供discord成员函数使用。我试过了:

    • bot.say(消息)
    • bot.say(消息、频道、消息)
    • bot.发送消息(message)
    • bot.send_消息(message.channel,message)

    预期结果是bot“说出”用户的消息,例如 !say Hello 机器人会回复“你好”

    1 回复  |  直到 7 年前
        1
  •  0
  •   PLASMA chicken    7 年前

    你必须使用 channel.send() 例如:

    @bot.command()
    async def foo(ctx, arg):
        await ctx.send(arg)
    

    您可以在以下位置看到更多解释的示例: https://discordpy.readthedocs.io/en/rewrite/ext/commands/commands.html