因此,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")
我不确定问题可能出在哪里,因为机器人内部的所有其他命令都工作正常。
答案 0 :(得分:0)
您可以使用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}".)