discord 机器人不会在控制台中显示消息

问题描述 投票:0回答:1
from discord.ext import commands
import data_bot

intents = discord.Intents.default()
bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    print('Bot is ready!')

@bot.event
async def on_message(message):
    if message.author.bot:
        return  # Ігнорує повідомлення від інших ботів

    print(f"{message.author}: {message.content}")

    await bot.process_commands(message)


bot.run(data_bot.TOKEN)

enter image description here 我是编程初学者,想编写一个 Discord 机器人,它可以在控制台中显示服务器上的所有消息。不幸的是,机器人本身不输出文本。我不明白问题是什么。

discord.py python-3.12
1个回答
0
投票

您缺少消息内容特权意图。如果没有这个,所有消息都将是空的。必须在代码和开发人员门户中启用此功能。

intents = discord.Intents.default()
intents.message_content = True

在开发者门户上,您首先创建了机器人:

© www.soinside.com 2019 - 2024. All rights reserved.