首页 > 解决方案 > 我在使用 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')

标签: pythondiscord.py-rewrite

解决方案


您之前缺少一个“@”client.command(pass_context=True)

这意味着您确实成功地删除了默认帮助命令,但是由于那个拼写错误,您的自定义帮助命令永远不会创建。因此,当您尝试运行帮助命令时,它会说它不存在。

discord.py 1.4.0 关于定义命令的文档:https ://discordpy.readthedocs.io/en/latest/ext/commands/commands.html


推荐阅读