Home > other >  get user mentions from Discord.py 2.0 interactions
get user mentions from Discord.py 2.0 interactions

Time:09-05

Using discord.py 2.0's new slash commands, how do I get mentions from discord.Interaction?

tree = discord.app_commands.CommandTree(client)


@tree.command(name="test", description="test")
async def test(interaction: discord.Interaction, message: str):
# ...

I am able to parse through the message param for user id's. But I was wondering if there is an easier way to maybe get a list of mentions instead of having to parse through it. If I try to print interaction.message I get None in return.

CodePudding user response:

As far as I know, it's not possible to get the mentions trough the library, like Result


Edit

It exists something called Transformer which allows this, but in my opinion it's unnecessarily complicated for your problem. But in case you want to use it:

Docs: https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.Transformer
Example: https://github.com/Rapptz/discord.py/blob/master/examples/app_commands/transformers.py

  • Related