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.
@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)
CodePudding user response:
A way of doing this would be when you execute your command, it modifies the role "everyone" so that they cant ping the role
Admins bypass ALL restrictions so they would still be able to ping the role besides
CodePudding user response:
You can use allowed_mentions
for this. Two ways of using this:
- Pass in
Bot
when initializing:
client = bot(.....,
allowed_mentions = discord.AllowedMentions(everyone = False)
)
- 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