【问题标题】:message.content is empty for bot client (pycord)机器人客户端(pycord)的 message.content 为空
【发布时间】:2022-11-03 07:43:31
【问题描述】:

我有最简单的不和谐机器人python程序

from discord.ext import commands

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

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

bot.run('token')

它只打印空字符串。在此之前我尝试了 bot.command() 但 bot 根本没有响应它可能是因为消息是空的,所以就像没有命令一样。我看到这个问题主要发生在 selfbot 客户端,但在我的情况下,客户端是 bot。很高兴有任何帮助

【问题讨论】:

  • 什么问题?也许有时系统会发送空消息-也许您应该跳过它们(使用if/else
  • 也许您应该将此作为问题发送给作者:github.com/Pycord-Development/pycord
  • 我无法在 Python 3.9、py-cord 2.0.0、Linux Mint 20.3 上重现您的问题
  • pycord 需要意图可能会尝试启用它可能开始工作的意图

标签: python discord pycord


【解决方案1】:

您必须在 https://discord.com/developers/applications 上启用 message 意图 并需要将它们传递给您的commands.Bot

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

将是如何做到这一点的一个例子。

【讨论】:

    猜你喜欢
    • 2022-12-09
    • 1970-01-01
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 2013-11-30
    • 2016-08-21
    • 2020-06-28
    相关资源
    最近更新 更多