How do I make it so that you can't @everyone with an echo command

Viewed 265

I want to add a way so that you cannot ping roles with the echo command. The only way I can think of is to check if 'content' starts with @ then it just responds with a message saying no, how can I do that?

@client.command()
async def echo(ctx, *, content:str):
    await ctx.send(content)
    print("Echo command works")
2 Answers

We can control pings in a message we send with allowed_mentions,

allowed_mentions = discord.AllowedMentions(everyone=False) 
await ctx.send(content, allowed_mentions=allowed_mentions)

This will successfully send the echo, even if there is an everyone ping, but will not ping everyone. If you want to reply to the user saying No, we have to check for mentions and reply.

mentions = ctx.message.role_mentions
if any([mention.is_default() for mention in mentions]): # there is an everyone mention
    return await ctx.send('No')
else:
    # do stuff

References:

You could use character in string like so:

@client.command()
async def echo(ctx, *, content:str):
    if "@" in content:
        return await ctx.send("No")
    await ctx.send(content)
    print("Echo command works")
Related