首页 > 解决方案 > 如何修复 discord.ext.commands.errors.CommandNotFound: Command "image" is not found 错误?

问题描述

我正在尝试构建一个 Discord 机器人,当您键入 .image 我正在使用 python 时,它将从我的计算机发送屏幕截图

我的代码

import Discord
from discord.ext import commands
client=commands.Bot(command_prefix=".")
@client.event
async def on_ready():
    print("Pokrenut")

@client.command()
async def image(ctx):
    await ctx.send(file=discord.File(r'C:\Users\Borna\Desktop\Programiranje2\0.png'))
client.run("My token")

当我在不和谐中键入 .image 时,什么也没有发生,但我在终端中收到错误

Pokrenut
Ignoring exception in command image:
Traceback (most recent call last):
  File "C:\Users\Borna\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\Borna\Desktop\Programiranje2\Discord.py", line 10, in image
    await ctx.send(file=discord.File(r'C:\Users\Borna\Desktop\Programiranje2\0.png'))
NameError: name 'discord' is not defined

The above exception was the direct cause of this following exception:

Traceback (most recent call last):
  File "C:\Users\Borna\anaconda3\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\Borna\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\Borna\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'discord' is not defined
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "image" is not found
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "image" is not found

标签: pythondiscorddiscord.pybots

解决方案


问题是您导入了Discord,但随后您discord在 image 命令中引用。尝试替换import Discordimport discord.

我不确定为什么它说“找不到命令图像”,可能是 discord.py 的错误并且没有正确处理错误。


推荐阅读