Say command that disables @everyone for non-administrators

EDIT: I have fixed the code by just using another method, thanks for the other helpful answers though!

I’m making a say command, it just takes the user’s message and repeats it via the bot. But it can be abused to ping everyone etc. So I want to make it so when the User isn’t an admin it checks the message for @everyone or @here. Then it says that you can’t ping everyone and reacts to the output ‘You cant ping everyone’ message with a custom command. It’s also in a cog btw. The command, when used, doesn’t throw any console errors, instead not doing anything. EDIT: I have fixed the code by just using another method, thanks for the other helpful answers though!

    @commands.command()
    async def say(self, ctx, *, message):
        await ctx.message.delete()
        if not ctx.message.author.guild_permissions.administrator:
            if "@everyone" in message or "@here" in message:
                antiping = "You can't mention everyone through me!"
                await ctx.send(antiping)
                await antiping.add_reaction(emoji=':Canteveryone:890319257534103603')
                return
        else:
            await ctx.message.delete()
            await ctx.send(message)

Answer

You can use allowed_mentions for this. Two ways of using this:

  1. Pass in Bot when initializing:
client = bot(.....,
          allowed_mentions = discord.AllowedMentions(everyone = False)
)
  1. You can also pass the same object when sending a message:
ctx.send(...,
         allowed_mentions = discord.AllowedMentions(everyone = False)
)

I’d recommend you read the docs for more info on how it works.

You can adjust mentions for the following attributes:

  • everyone
  • replied_user
  • roles
  • users