Ask coding questions

← Back to all posts
How do i add the prefix to the commands? [Discord.py]
h
Lumiscnt (1)

So i need some help, whenever i try coding my bot to say somthing, such as &ping, i want it to be so that when i add the command, and i run it, the prefix '&' and the command 'ping' will show the ping. This shall go for any other commands too. How do i do this?

Comments
hotnewtop
AloegelhiPlaysR (109)

Adding & before every command. So instead of checking for help, try checking for &help

Lumiscnt (1)

@AloegelhiPlaysR so if i get this correctly

@client.command()
async def on_message(message):
     if message.content.startswith('&help'):
	 async def ping():
     await client.say(f'Pong! {client.latency}')

what i mean is, where and what do i add to make my commands display the command when inputting &ping?

Like for this command:

@client.command()
async def who(ctx):
    member = ctx.message.author
    roles = [role.mention for role in member.roles[1:]]  # don't get @everyone
    roles.append('@everyone')  # set string @everyone instead of role
    await ctx.send(" ".join(roles))

i want to add the prefix & to this but how?

tristans2 (0)

@Lumiscnt just replace "user_input" with whatever variable contains the user input

if user_input[0] != "&":
    # enter some failure state and return
user_input = ''.join(user_input[1:])
Lumiscnt (1)

@tristans2 thanks, i figured it out anyways!