如何修复 discord.ext.commands.errors.CommandNotFound:找不到命令“图像”错误?

时间:2021-05-04 12:41:03

标签: python discord discord.py bots

我正在尝试构建一个 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")

当我在 discord 中输入 .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

1 个答案:

答案 0 :(得分:0)

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

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