【问题标题】:I get an error when 'await' is in front of client.send_message'await' 在 client.send_message 前面时出现错误
【发布时间】:2017-11-25 17:53:54
【问题描述】:

我正在使用 discord.py 版本 0.16.8。我的客户也是:client = discord.Client()

在写await client.send_message(All the usual code is in here) 时,我在等待时收到一条错误消息:
“类 'Message' 没有定义 'await',因此不能在其实例上使用 'await' 运算符”。

当我尝试在 Discord 中运行我的 Bot 并尝试我的命令之一时,它不起作用,并且没有消息弹出。这是我的命令代码:

@client.event
async def on_message(message):

    if message.content == '..roll':
    await client.send_message(message.channel, str(randint(1, 6)))

我们将不胜感激,谢谢!

【问题讨论】:

    标签: python async-await discord.py


    【解决方案1】:

    您好像忘记了 if 语句中的缩进

    @client.event
    async def on_message(message):
    
        if message.content == '..roll':
            await client.send_message(message.channel, str(randint(1, 6)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      相关资源
      最近更新 更多