【问题标题】:Python - Discord bot on ready send message to channelPython - 准备发送消息到频道的不和谐机器人
【发布时间】:2020-10-25 05:28:07
【问题描述】:

我在创建从终端执行时向默认通道发送消息的简单 python 脚本时遇到问题。

import discord

@bot.event
async def on_ready(ctx):
    print('Online')
    await ctx.send('Message sent!')


bot.run('MYTOKEN')

在这个例子中,我不断收到“ctx”未定义

【问题讨论】:

    标签: python bots discord


    【解决方案1】:

    这里的问题是on_ready 事件不应该接收任何参数。请参阅 Minimal Bot 文档 here 和事件参考 here 中的 on_ready 文档。如果您想在机器人连接时发送消息。您必须先get the channel object,然后使用发送方法。您可以在文档here的常见问题部分中找到获取频道和发送消息的示例@

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 1970-01-01
      • 2020-12-23
      • 2021-06-17
      • 2020-12-18
      • 2020-09-02
      • 2020-05-11
      • 2022-11-02
      • 1970-01-01
      相关资源
      最近更新 更多