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

Discord机器人仅能在私聊中响应,如何解决该问题?

Discord机器人仅私聊响应、群聊无响应的解决方法

问题出在Discord的**网关权限(Intents)**配置上,默认权限不包含读取群聊消息内容的权限,导致机器人无法接收群聊中的消息。解决需要两步操作:

1. 在Discord开发者平台开启消息内容权限

登录Discord开发者平台,找到你的机器人应用,进入「Bot」页面,在「Privileged Gateway Intents」区域,开启「Message Content Intent」选项。

2. 修改代码中的Intents配置

原代码使用discord.Intents.default(),该配置默认不包含消息内容权限,需要手动添加。修改后的代码如下:

import discord
import random
import time
import asyncio

token = "你的机器人令牌"

# 配置包含消息内容权限的Intents
intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)


@client.event
async def on_ready():
    print(f"Bot logged on as {client.user}")


@client.event
async def on_message(msg):
    if msg.author == client.user:
        return
    if msg.content.lower().startswith("?hi"):
        await msg.channel.send(f"Comrade {msg.author.display_name}, will you assist me in seizing the means of production?")

client.run(token)

说明:Discord的新权限机制要求,机器人读取消息内容必须显式开启message_content权限,私聊场景因直接交互不受此限制,但群聊必须同时完成平台端和代码端的权限配置,机器人才能正常接收并处理群聊消息。

内容的提问来源于stack exchange,提问作者Rimants Šiupienis

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 08:45:37