Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading