You need to enable JavaScript to run this app. discord.py中.clear删除所有频道命令无法识别、CommandNotFound报错问题
优惠活动
大模型
产品
解决方案
定价
更多

discord.py中.clear删除所有频道命令无法识别、CommandNotFound报错问题

问题现象

开发了一款Discord机器人,预期实现触发指令为.clear的删除所有频道功能,其余命令运行均无异常,也不存在重名的clear命令,但出现以下异常:

  • 调用.help时clear命令不展示
  • 执行.clear指令无响应
  • 收到报错信息:

Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "clear" is not found

原错误代码
import discord
from discord.ext import commands
import random
from discord import Permissions
from colorama import Fore, Style
import asyncio
#imports for reference

@client.command
@commands.is_owner()
 async def clear(ctx):
    await ctx.message.delete()
    guild = ctx.guild
    for channel in guild.channels:
     try:
      await channel.delete()
      print (Fore.GREEN + f"{channel.name} was deleted" + Fore.RESET)
     except:
        print (Fore.RED + f"{channel.name} was not deleted" + Fore.RESET)
        return
错误原因

装饰器书写错误,误写为@client.command,该写法没有完成命令装饰器的初始化调用,导致机器人无法识别并注册该命令。

修复方案

将命令装饰器修改为带括号的调用形式@client.command()即可,修改后机器人会正常注册clear命令,对应功能可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.12 17:18:03