Is there a specific mention object for commands?

Viewed 46

So right now I'm trying to figure out how to make my bot mention the role/member/everyone/here mention when a user uses it in a command but there is an issue. I can either make it so that it recognises roles or members separately. Is there a way to ignore that and just get whatever mention the user uses?

@bot.command()
@has_permissions(administrator=True)
async def announce(ctx, tit : str = None, desc : str =  None, user : discord.Role = None):
  if tit and desc:
    if mention:
      await ctx.channel.send(content = user.mention)

Whenever I use it on @here, for example, I get this error:

discord.ext.commands.errors.RoleNotFound: Role "@​here" not found.
1 Answers

You can use Message.mentions and Message.role_mentions, which are lists of mention and role objects.

For @everyone and @here, you can use Message.mention_everyone. Unfortunately this is only a bool and not an object. This is True if either @everyone or @here is mentioned.

Message.channel_mentions can also be checked for a list of channel and thread objects.

@bot.command()
@has_permissions(administrator=True)
async def announce(ctx, tit : str = None, desc : str =  None):
    if tit and desc:
        for mention in ctx.message.mentions:
            await ctx.channel.send(content = mention)
        for role_mention in ctx.message.role_mentions:
            await ctx.channel.send(content = role_mention)
        for channel_mention in ctx.message.channel_mentions:
            await ctx.channel.send(content = channel_mention)
        if ctx.message.mention_everyone:
            await ctx.channel.send('everyone or here was mentioned')
Related