簡體   English   中英

在不和諧機器人中調用特定命令時找不到命令

[英]Command not found whenever a specific command is called in discord bot

所以,我的 discord bot 中的大多數命令都可以工作,但是每當我調用這個特定的命令時,我都會收到“找不到命令”的消息。 這是這些特定命令的代碼:

@client.command(pass_context = True)
async def pause(ctx):
    voice = get(client.voice_clients, guild=ctx.guild)
    if voice and voice.is_playing():
        print("Music paused")
        voice.pause()
        await ctx.send("Music paused")
    else:
        print("Music not playing")
        await ctx.send("Music not playing, failed pause")


@client.command(pass_context = True)
async def resume(ctx):
    voice = get(client.voice_clients, guild=ctx.guild)
    if voice and voice.is_paused():
        print("Resumed Music")
        voice.resume()
        await ctx.send("Resumed music")
    else:
        print("Music is not paused")
        await ctx.send("Music not paused, failed to resume")


@client.command(pass_context = True)
async def stop(ctx):
    voice = get(client.voice_clients, guild=ctx.guild)
    if voice and voice.is_playing():
        print("Music stopped")
        voice.stop()
        await ctx.send("Music stopped")
    else:
        print("Music not playing")
        await ctx.send("Music not playing, failed to stop")

我不確定可能是什么問題,因為機器人內部的所有其他命令都可以正常工作。

您可以使用on_command_error函數。

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        await ctx.send(add a custom message, or you can do f"{error}".)
        return

如果您想為每個命令自定義錯誤,可以使用。

@commandname.error
async def commandname_error(ctx, error):
    if isinstance(error, commands.errorname):
        await ctx.send(add a custom message, or you can do f"{error}".)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM