简体   繁体   English

机器人客户端(pycord)的 message.content 为空

[英]message.content is empty for bot client (pycord)

I have simplest python program of discord bot我有最简单的 discord 机器人 python 程序

from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_message(msg):
    print(msg.content)

bot.run('token')

And it prints just empty string.它只打印空字符串。 Before that I tried bot.command() but bot simply doesn't responds to it probably because message is empty so like there's no command.在此之前我尝试了 bot.command() 但 bot 根本没有响应它可能是因为消息是空的,所以就像没有命令一样。 I saw this problem mostly occurs for selfbot clients but in my case client is bot.我看到这个问题主要发生在 selfbot 客户端,但在我的情况下,客户端是 bot。 Would be glad for any help很高兴有任何帮助

You have to enable the message intents on https://discord.com/developers/applications and need to pass them to your commands.Bot您必须在https://discord.com/developers/applications上启用message意图,并且需要将它们传递给您的commands.Bot

bot = commands.Bot(command_prefix="!", intents=discord.Intents.all()

would be an example of how you can do that.将是如何做到这一点的一个例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM