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

Discord Python Bot无法读取消息,运行菜单无消息显示求助

Discord Python Bot无法读取消息/响应命令的解决方案

核心问题:Intent配置不全

discord.py v2.0及以上版本中,**消息内容读取(Message Content)**是独立的特权Intent,默认处于关闭状态。仅开启intents.messages = True无法让Bot获取消息文本内容,自然无法触发命令。

修复步骤

  1. 更新代码中的Intent设置
    修改Intent初始化代码,添加消息内容权限:

    intents = discord.Intents.default()
    intents.typing = False
    intents.messages = True
    intents.message_content = True  # 新增:启用消息内容读取权限
    intents.presences = True
    intents.voice_states = True
    
  2. 在Discord开发者后台开启对应特权Intent
    打开Discord开发者平台,找到你的Bot应用,进入「Bot」页面,在「Privileged Gateway Intents」板块,开启「Message Content Intent」开关并保存设置。

额外检查项

  • 服务器权限验证
    确认Bot的服务器角色拥有以下必要权限:

    • 查看频道(View Channel)
    • 发送消息(Send Messages)
    • 读取消息历史(Read Message History)
    • 连接语音频道(Connect)、发言(Speak)(针对语音功能)
  • 命令前缀核对
    确保聊天中使用的命令前缀与代码设置的!一致,比如发送!join而非其他前缀。

  • 依赖库兼容性提示
    youtube_dl已停止维护,后续可能出现失效问题,建议替换为yt-dlp:

    • 安装:pip install yt-dlp
    • 代码替换:将import youtube_dl改为import yt_dlp as youtube_dl,现有逻辑无需其他修改。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 16:35:22