Skip to content Skip to sidebar Skip to footer

How Can I Properly Parse For A Tagged User In My Discord Bot?

I am adding profile cards onto my Discord bot, but I've come across one issue. When someone types !profile @user I am not sure how to properly parse for @user so the bot knows whic

Solution 1:

discord.py's message objects include a Message.mentions attribute so you can iterate over a list of Member. Here are the doc listings for async and rewrite.

With this you can simply iterate over the mentions as so:

formemberin ctx.message.mentions:
    # do stuff withmember

what you actually want

discord.py allows you to grab discord.Member objects from messages with type hinting. simply add the following to the command

@bot.command()asyncdefprofile(ctx, member: discord.Member=None):
    member = member or ctx.message.author

Post a Comment for "How Can I Properly Parse For A Tagged User In My Discord Bot?"