Search code examples
discordnamesmention

How to get all the names from message.mentions (discord bot)


I'm having trouble getting the names from the message.mentions string, because there can be more than one name.

I didn't find any method anywhere, message.mentions[0] doesn't work, neither does message.mentions.name or something like that.

Is there a simple way to do it?

This is what message.mentions can contain: [<Member id=1039533025127583754 name='karlosbotospicus' discriminator='0831' bot=True nick=None guild=>, <Member id=431438830504247299 name='metrix' discriminator='4505' bot=False nick='Vašek' guild=>]

I also included the libraries I use, some of them are irrelevant to this problem

import smtplib
from email.message import EmailMessage
from email.utils import formatdate
from pprint import pprint
import os 
import discord
from discord.ext import commands
from dotenv import load_dotenv
from typing import Tuple, Any, List
import anything

from dotenv import load_dotenv  

@bot.event
async def on_message(message):
    if message.mentions:
        await message.channel.send(message.mentions)

Solution

  • for menti in message.mentions:
        id = menti.id