不和谐机器人 (py) 不要回复任何服务器上的消息,而是回复直接 dms



Discord bot(py(不回复任何服务器上的消息,而是回复直接dms

我使用discord.py和python构建了一个discordBot,在我编写(示例$hello(时,它只在私有dms上回复,而不在任何服务器上回复消息。我已经在服务器上给了机器人管理员,但仍然没有做任何事情。

我的py代码是:

intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
async def on_message(message): 
if message.content.startswith('$hello'):
print(message.content)
await message.channel.send('Hello')
client.run(token)

此外,如果我在dc服务器上发送消息,它不会向控制台写入任何内容。

没有防火墙规则可以解决这个问题。

确保在开发者门户中切换机器人意图

如果你启用了它,你可以尝试启用所有的意图,然后把它放在意图参数中

client = discord.Client(intents=discord.Intents().all())

代码可能看起来像这个

import discord
client = discord.Client(intents=discord.Intents().all())
async def on_message(message): 
if message.content.startswith('$hello'):
print(message.content)
await message.channel.send('Hello')
client.run(token)

作为一个快速提示:根据不一致的API参考;on_message(("函数,需要将Intents.messages设置为True。在你的情况下,这将是

intents.messages = True

我没有测试这个代码,但它是我从不和谐的文档中读到的。以后你可能想看看https://discordpy.readthedocs.io/en/stable/

我希望我能帮你快速回答:(

最新更新