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

Replit上的Discord Bot在线但无响应问题求助

Discord Bot 无法响应 $hello 命令的解决方法

问题原因

你的Bot无法响应消息命令,核心原因是没有启用Message Content Intent。从v2.0版本开始,discord.py默认不会开启消息内容权限,而你的代码里仅使用discord.Intents.default(),该配置不包含读取消息内容的权限。

修复步骤

1. 修改代码中的Intents配置

将客户端初始化代码调整为包含message_content=True的完整Intents配置:

import discord
import os

# 配置Intents,添加消息内容读取权限
intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
  print("This is user {0.user}".format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return
  if message.content.startswith("$hello"):
    await message.channel.send("Hello!")

my_secret = os.environ['TOKEN']

client.run(my_secret)

2. 在Discord开发者平台启用对应权限

  • 进入Discord开发者门户,打开你的Bot应用页面
  • 切换到「Bot」标签页
  • 在「Privileged Gateway Intents」区域,找到「Message Content Intent」并开启
  • 保存设置后,重启Replit上的Bot进程

完成以上操作后,Bot即可正常响应$hello命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 16:32:23