python - 我在使用 discord.py 时遇到问题,我的命令之一无法被识别
问题描述
事情是这样的,我正在使用最新版本的 discord.py 来编写一个不和谐的机器人,我被困住
了我已经制作了一个自定义帮助命令,在此之前我已经使用这一行删除了旧的帮助命令:
client.remove_command("help")
虽然当我运行它时(顺便说一句,它没有吐出错误)并尝试该命令,但它说
discord.ext.commands.errors.CommandNotFound:找不到命令“帮助”
这是完整的代码:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
client.remove_command("help")
@client.event
async def on_ready():
print('bot is ready.')
client.command(pass_context=True)
async def help(ctx, member : discord.Member):
author = ctx.message.author
embed = discord.Embed(
colour = discord.Colour.orange()
)
embed.set_author(name='Help', value="Sends you this embed in a private message")
embed.add_field(name='.ping', value="Shows the bot's current ping.", inline=False)
await author.send(embed=embed)
await ctx.send(f"{member.mention} Check you dms, i've sent you a private message! *wink*")
client.run('TOKEN HERE')
解决方案
您之前缺少一个“@”client.command(pass_context=True)
这意味着您确实成功地删除了默认帮助命令,但是由于那个拼写错误,您的自定义帮助命令永远不会创建。因此,当您尝试运行帮助命令时,它会说它不存在。
discord.py 1.4.0 关于定义命令的文档:https ://discordpy.readthedocs.io/en/latest/ext/commands/commands.html
推荐阅读
- datetime - Timex.to_naive_datetime 减去一个小时
- php - 调用未定义的方法 codeigniter Modeloproduccion::obtener_produccion_por_id()
- c# - ArgumentNullException:值不能为空。参数名称:items selectlist .net core
- python-3.x - 无法与 Pymodbus TCPserver 建立连接
- java - 如何使用 Jackson 反序列化空类型 JSON 字段
- python - 有效地从列表中删除重复元素和类似元素
- groovy - 存储 gremlin 计数值并稍后在遍历中进行比较
- scala - 如何在 spark 2.4.3 的 reduce rdd 中覆盖元组的哈希函数?
- python - 无法让 tesseract 在 python 上工作
- angular - 在 @NgModule 装饰器中调用函数