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

Replit部署Discord机器人>hello命令无响应及无法连接语音求助

问题根因

  • 你使用的discord.py v2.x及以上版本要求显式开启message_content权限才能识别前缀指令,你当前只开启了members意图,机器人无法读取消息内容自然响应不了指令
  • keep_alive函数未提前导入,代码运行会直接抛出异常无法正常启动
  • pass_context是discord.py旧版本参数,新版本已经默认传递上下文,冗余参数不影响运行但可以删除
  • 你还需要在Discord开发者后台的机器人设置页,开启特权网关意图中的Message Content Intent和Server Members Intent开关,否则代码中声明的意图不会生效

修复步骤

  1. 补全缺失的意图声明,添加message_content开启配置
  2. 导入keep_alive函数(如果是replit平台的保活脚本,需要提前在同目录下写好keep_alive.py文件)
  3. 移除冗余的pass_context参数
  4. 确认Discord开发者后台对应特权开关已开启

修复后完整代码

import discord
import os
from discord.ext import commands
# 导入保活函数
from keep_alive import keep_alive

intents = discord.Intents.default()
intents.members = True
# 新增消息内容意图开启
intents.message_content = True
client = commands.Bot(command_prefix = '>', intents=intents)

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

@client.command()
async def hello(ctx):
    await ctx.send("Hello Im Deemo Bot")

@client.command()
async def join(ctx):
  if ctx.author.voice:
    channel = ctx.message.author.voice.channel
    await channel.connect()
  else:
    await ctx.send('You are not in a voice channel')

@client.command()
async def leave(ctx):
  if ctx.voice_client:
    await ctx.guild.voice_client.disconnect()
    await ctx.send('Deemo left voice')
  else:
    await ctx.send('Deemo is not in voice')

keep_alive()
client.run(os.environ['TOKEN'])

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 14:15:05