简体   繁体   中英

Discord Python Command Arguments

I'm trying to make a command where the second argument is what the bot will actually do

,haha kick, !haha ban, !haha test

so I have

bot = commands.Bot(command_prefix='!')

@bot.command()
async def haha(ctx, arg):
    channel = bot.get_channel(591059696622895117)
    try:
        if (arg == "kick"):
            #kick 
        elif (arg == "ban"):
            #ban
    except:
        await channel.send("Error processing your request!")
        pass

however I run into an error when I run !haha since it's missing arguments, what am I missing?

If you mean commands.errors.MissingRequiredArgument, It's a feature, not a bug. You can handle it with command_error event.

@bot.event
async def on_command_error(ctx, error):
  if isinstance(error, commands.errors.MissingRequiredArgument):
    await ctx.send("Your command isn't right!\n Read the help")
  else:
    raise error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM