python - 如何修复 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
解决方案
问题是您导入了Discord
,但随后您discord
在 image 命令中引用。尝试替换import Discord
为import discord
.
我不确定为什么它说“找不到命令图像”,可能是 discord.py 的错误并且没有正确处理错误。
推荐阅读
- c# - 亚马逊 MWS 更新跟踪号
- amazon-s3 - 如何在 Kubernetes 的 fluentd-kubernetes-daemonset 中添加多个输出
- go - 从本地系统获取当前位置区域
- javascript - 在回调函数中创建的对象未定义
- css - sass亮度函数查询
- javascript - 一旦满足特定条件,如何禁用点击事件?
- c# - 使用while循环在二维数组列表中的C#用户输入选择
- php - preg_match_all 输出 PHP 中的奇怪数组结构
- c++ - 使用 new 声明数组后的 delete[] 关键字导致错误
- mysql - MySQL Workbech ERROR 1064 Insert 问题不知道出在哪里?