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)
我是编程初学者,想编写一个 Discord 机器人,它可以在控制台中显示服务器上的所有消息。不幸的是,机器人本身不输出文本。我不明白问题是什么。
您缺少消息内容特权意图。如果没有这个,所有消息都将是空的。必须在代码和开发人员门户中启用此功能。
intents = discord.Intents.default()
intents.message_content = True