【问题标题】:Function "say" throws up an AttributeError: 'str' object has no attribute 'channel' error函数 "say" 抛出 AttributeError: 'str' object has no attribute 'channel' 错误
【发布时间】:2019-06-09 19:37:11
【问题描述】:

我正在使用 @bot.command() 功能设置一个新的不和谐机器人,但是,我的 !say 命令不会接受用户的输入,然后让机器人说出它

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

这是一个不和谐的服务器,机器人是为我自动管理事情以及提供不和谐成员使用的功能。我试过了:

  • bot.say(消息)
  • bot.say(message.channel, message)
  • bot.send_message(消息)
  • bot.send_message(message.channel, 消息)

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

【问题讨论】:

    标签: python python-3.x discord.py discord.py-rewrite


    【解决方案1】:

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

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

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

    【讨论】:

    • @Mooles 如果这解决了您的问题,您能否通过单击左侧的勾号来接受这个答案?这会将您的问题标记为已解决;)
    • 抱歉,Stack Overflow 还是新手
    猜你喜欢
    • 2020-12-29
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多