user17507616
user17507616

Reputation:

How do I make a Discord bot that has more than one command?

I am trying to make a discord bot but when I try to add another command the second command isn't recognised. here is the relevant code:

@bot.command()
async def parrot(ctx, *, arg):
    await ctx.channel.send(arg)

async def talkparrot(ctx, *, arg):
    await ctx.channel.send(arg, tts=True)

When I type ".parrot arg1" it works fine but ".taklparrot arg1" doesn't work. Why is this?

Upvotes: 0

Views: 188

Answers (2)

Alan Bagel
Alan Bagel

Reputation: 911

You need to apply the decorator multiple times:

@bot.command()
async def parrot(ctx, *, arg):
    await ctx.channel.send(arg)

@bot.command()
async def talkparrot(ctx, *, arg):
    await ctx.channel.send(arg, tts=True)

Now the bot.command() decorator will be applied to both functions. You can apply the decorator for as many commands as you need. Do not apply this decorator to every function, though, only commands.

Upvotes: 2

12944qwerty
12944qwerty

Reputation: 1925

In order to make commands you can add the shortcut decorator to a function and it will convert that function into a command.

This is also repeatable so you don't have to do it for just one command, it will do it for every function you want.

Upvotes: 1

Related Questions