如何创建2字命令discord.py?

时间:2020-11-12 01:35:01

标签: python bots 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

1 个答案:

答案 0 :(得分:1)

您可以通过两种方式解决此问题。

一种方法是创建一个命令“ voice”,然后以args形式打开和关闭它。

@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