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

Replit中discord.ext运行报错:依赖冲突与Callback重复命令问题

问题解决步骤

1. 处理依赖冲突警告

你的环境中同时安装了discord.py、discord与nextcord,这几个库存在兼容性冲突。执行以下命令卸载冲突库:

pip3 uninstall discord.py discord -y

2. 修复命令重复注册错误

查看代码可知,Hello命令上方多了两个未绑定对应函数的装饰器:

@client.command(pass_context=True)
@has_permissions(manage_roles=True)

这两行代码没有关联任何函数,直接作用到了下方的@client.command()和Hello函数上,导致同一个函数被两次标记为命令,触发TypeError: Callback is already a command.错误。

删除这两行多余代码后,Hello命令的正确代码如下:

@client.command()
async def Hello(ctx):
  await ctx.send('Hi')

修改后的完整代码

import discord
from discord.ext import commands
import os
from discord import Member
from discord.ext.commands import MissingPermissions
from discord.ext.commands import has_permissions


intents = discord.Intents.default()
intents.members=True

client = commands.Bot(command_prefix="~$", intents=intents)

#######Events######
@client.event
async def on_ready():
  print("Bot is up and ready!")
  await client.change_presence(activity=discord.Game('ERLC'))

@client.event
async def on_member_join(member):
  await member.send("Welcome to the mafia!")
  

######Commands#######

@client.command()
async def Hello(ctx):
  await ctx.send('Hi')

@client.command()
@has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
  await member.kick(reason=reason)
  await ctx.send(f"User {member} has been kicked.")
  
@kick.error
async def kick_error(ctx, error):
  if isinstance(error, commands.MissingPermissions):
    await ctx.send("You do not have permissions to kick.")

@client.command()
@has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason=None):
  await member.send("You have been banned")
  await member.ban(reason=reason)
  await ctx.send(f"User {member} has been banned.")
  
@ban.error
async def ban_error(ctx, error):
  if isinstance(error, commands.MissingPermissions):
    await ctx.send("You do not have permissions to ban.")

client.run(os.getenv("TOKEN"))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 21:30:53