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

Discord.py运行unmute命令报错'coroutine' object is not callable如何解决?

报错解决方案

核心错误点

你使用的权限校验装饰器写法错误,@commands(manage_messages=True) 不符合discord.py的规范,正确的权限校验装饰器为 commands.has_permissions(),错误调用协程对象就会触发'coroutine' object is not callable报错。

修正后的完整代码

@bot.command(description="Unmutes a specified user.")
@commands.has_permissions(manage_messages=True)  # 修正了装饰器写法
async def unmute(ctx, member: discord.Member):
   mutedRole = discord.utils.get(ctx.guild.roles, name="Muted")
   # 额外增加判空逻辑,避免Muted角色不存在时报错
   if not mutedRole:
       await ctx.send("当前服务器未找到Muted禁言角色")
       return
   await member.remove_roles(mutedRole)
   # 修复拼写错误,同时捕获私信发送失败的异常(用户可能关闭了私信权限)
   try:
       await member.send(f"你已在 {ctx.guild.name} 服务器被解除禁言")
   except:
       pass
   embed = discord.Embed(title="解除禁言成功", description=f"已解除 {member.mention} 的禁言",colour=discord.Colour.green())
   await ctx.send(embed=embed)

额外注意事项

  • 确保你的机器人账号拥有 管理角色 权限,否则无法移除用户的Muted角色
  • 建议把Muted角色的权限优先级调到机器人角色之下,否则机器人无法操作用户的该角色

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 21:18:02