Skip to content Skip to sidebar Skip to footer

Mentioning Users And Self With Discord.py

I'm still really new to coding and the only way I can get this command to work is by doing what I'm doing below. I'm pretty sure there's a better way to write it, but it's not exac

Solution 1:

You can use the User.mention attribute to get a string that will mention the given user. This applies to the message.author as well. If you have multiple messages you're choosing from, it will simplify your code to select the correct template and then fill in the mentions

elif message.content.startswith('!sayhello'):
    user = message.mentions[0]
    responses = ["{} says hello to {}", "{} says hi to {}", "{} waves to {}"]
    choice = random.choice(responses)
    choice = choice.format(message.author.mention, user.mention)
    await client.send_message(message.channel, choice)

Post a Comment for "Mentioning Users And Self With Discord.py"