我如何让我的Python Discord bot模仿所有发送的消息?

问题描述 投票:1回答:1

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

我试过这个:

@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-3.x discord.py
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.