首页 > 解决方案 > 如何创建一个 2 字命令 discord.py?

问题描述

我想让机器人感知,例如,命令 .voice 打开,但给出错误

Command "voice" is not found
@commands.command(
    name = "closevoice",
    aliases = ["voice close"],
    usage = "voice close",      
  )
  async def voice_close(self, ctx):
    pass

标签: pythonbotsdiscord.py

解决方案


你可以通过两种方式解决这个问题。

一种方法是创建一个命令“声音”,并将其作为参数打开和关闭。

@bot.command()
async def voice(self, ctx, arg1):
    if arg1 == "open":
        # DO SOMETHING
    elif arg1 == "close":
        # DO SOMETHING ELSE

或者,您可以让机器人监视消息并查找“语音打开”和“语音关闭”,而不是发出命令。

@bot.event
async def on_message(message):
    if message.content == "voice open":
        # DO SOMETHING
    elif message.content == "voice close":
        # DO SOMETHING ELSE

推荐阅读