【问题标题】:How would I make my Python Discord bot mimic all messages sent?如何让我的 Python Discord 机器人模仿所有发送的消息?
【发布时间】:2018-06-02 11:32:29
【问题描述】:

我正在使用 Python (v. 3.6.1) 编写一个 Discord 机器人。它的功能之一是检测通道中发送的所有消息,对其进行处理,然后响应所述通道中的消息。 (至少,这是我想要它做的。)

我试过这个:

@bot.event
async def on_message(message):
    await bot.say(message.content)

该函数在发送消息时响应,但不是以我想要的方式响应。相反,我得到一个错误:

discord.errors.InvalidArgument: Destination must be Channel, PrivateChannel, User, or Object. Received NoneType

我将如何解决这个问题?非常感谢!

【问题讨论】:

  • 对于python问题总是使用通用的[python]标签
  • 请包含给您带来麻烦的代码。单独的错误消息是没有用的。见How do I ask a good question?

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


【解决方案1】:

您不能在命令之外使用bot.say。

我可以在命令之外的其他地方使用 bot.say 吗?

没有。由于所涉及的魔法工作方式,它们只能在命令内部工作。

http://discordpy.readthedocs.io/en/latest/faq.html#can-i-use-bot-say-in-other-places-aside-from-commands

要让机器人重复发送的每条消息,您可以使用send_message。下面是一个例子。

@client.event
async def on_message(message):
    await client.send_message(message.channel, message.content)

【讨论】:

    猜你喜欢
    • 2022-01-23
    • 2018-06-03
    • 2019-11-06
    • 2021-03-22
    • 2021-08-19
    • 2023-01-17
    • 2021-09-19
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多