You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

nextcord报Message content intent未启用 前缀命令异常如何排查

运行报错现象

运行nextcord项目时收到如下报错提示:

Message content intent is not enabled. Prefix commands may not work as expected unless you enable this.

已在Discord开发者后台开启所有intents权限,对应配置截图如下:
开发者后台Intents配置截图

作为首次接触discord.py/nextcord开发的新手,提供项目代码用于问题排查:

import nextcord
from nextcord import Interaction
from nextcord.ext import commands

intents = nextcord.Intents.default()
intents.members = True
command_prefix = '!'

client = commands.Bot(command_prefix, intents = intents)

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

testserver = 988598060538015815

@nextcord.slash_command(name = "hello", description = "Bot Says Hello", guild_ids = [testserver])
async def hellocommand(interaction: Interaction):
  await interaction.response.send_message("yoooo")


client.run("my token")

目前开发者后台已开启全部intents权限,仍然触发上述报错,前缀命令无法正常运行。

问题排查与解决
  • 报错核心原因:Discord的Intent权限需要开发者后台开启+代码侧显式声明启用两个步骤同时完成才会生效,只在后台开权限、代码里不声明对应权限的话,库不会向Discord请求该权限,自然会触发报错。前缀命令依赖读取普通消息的文本内容,必须拿到message_content权限才能正常工作。
  • 你的代码里仅显式开启了members权限,没有开启message_content权限:nextcord.Intents.default()默认是关闭message_content权限的,和你后台开没开没有关系。
  • 修复方式二选一即可:
    • 方案1(仅推荐个人测试Bot使用):直接加载所有Intents,把intents初始化行替换为intents = nextcord.Intents.all()
    • 方案2(遵循最小权限原则,推荐):在原有intents配置下新增一行显式开启消息内容权限,修改后的intents配置段如下:
intents = nextcord.Intents.default()
intents.members = True
intents.message_content = True
command_prefix = '!'

client = commands.Bot(command_prefix, intents = intents)

修改完成后重启Bot,报错提示就会消失,前缀命令也可以正常响应。

内容的提问来源于stack exchange,提问作者Dominic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.29 14:03:28