【问题标题】:discord bot does not print message.contentdiscord bot 不打印 message.content
【发布时间】:2023-02-15 21:32:49
【问题描述】:

我正在使用以下代码在特定的不和谐频道上打印最新消息,但它总是带来一个空字符串。

from termcolor import colored
import discord

intents = discord.Intents.default()
intents.members = True
intents.messages = True

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

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    # Check if the message was sent in the specific channel you want to read from
    if message.channel.id == CHANNELID:  # replace CHANNEL_ID with the ID of the channel you want to read from
        print(colored(message.content, 'green'))

client.run('TOKEN')

有任何想法吗?

消息内容意图在应用程序上正确启用,并且机器人在频道上具有阅读消息和阅读消息历史记录的权限。

【问题讨论】:

    标签: python discord bots


    【解决方案1】:

    如果您的机器人没有设置意图,就会出现这种情况。

    转到 Discord Developer Portal 和您的 Bot,然后转到 Bot 并转到 Privilege Gateway Intents 并检查 Message Content Intent

    您已经在代码中指定了意图,所以应该这样做

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-15
      • 2022-10-14
      • 1970-01-01
      • 2019-09-05
      • 2022-01-04
      • 1970-01-01
      • 2022-10-21
      • 2021-07-03
      相关资源
      最近更新 更多