如何使Python Discord bot模拟发送的所有消息?

2024-06-09 08:37:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用Python(v.3.6.1)编写一个Discord bot。它的一个功能是检测在一个信道中发送的所有消息,对它们进行处理,然后对所述信道中的消息作出响应。(至少,这是我想要它做的事情。)

我试过了:

@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

我该怎么解决这个问题?非常感谢!在


Tags: 函数功能event消息messageasyncondef
1条回答
网友
1楼 · 发布于 2024-06-09 08:37:28

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

Can I use bot.say in other places aside from commands?

No. They only work inside commands due to the way the magic involved works.

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

要让bot重复发送的每个消息,可以使用send_message。下面是一个例子。在

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

相关问题 更多 >