Skip to content

Instantly share code, notes, and snippets.

@DuckMasterAl
Last active October 1, 2023 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DuckMasterAl/8caa846a9544350484c4c19471081186 to your computer and use it in GitHub Desktop.
Save DuckMasterAl/8caa846a9544350484c4c19471081186 to your computer and use it in GitHub Desktop.
How to Use Allowed Mentions (I stole this from @TheMoksej)

Trying to sanitize mentions? Here are few examples what you should use. Note: Make sure you're looking at your library example and you have the required library version or higher installed otherwise it won't work.

Discord.py (requires v1.4.0 or higher) There are multiple options:

  1. add , allowed_mentions=discord.AllowedMentions(roles=False, everyone=False) after the output of your command. (works for individual messages only)
  2. put it into client (if you do this, all messages your bot sends will ping nobody by default) ╠ Example 1 If you have it subclassed:
class Bot(commands.AutoShardedBot):
    def __init__(self, **kwargs):
        super().__init__(
            allowed_mentions = discord.AllowedMentions(roles=False, users=False, everyone=False),
        )

Example 2 If it's not subclassed:

bot = commands.Bot(allowed_mentions=discord.AllowedMentions(roles=False, users=False, everyone=False))

Example 1 taken from: https://github.com/TheMoksej/Dredd/blob/76ff9608af1bd5a09a89f523996d57103a83b471/bot.py#L107 Example 2 taken from: https://github.com/discordextremelist/bot/blob/915d203ca2b4ae4bbf9f55cb303c5dc5a4b17e8f/bot.py#L59

Discord.JS (requires v12.2.0 or higher) There are multiple options:

  1. add , {allowedMentions: {parse: []}} after the output of your command. (works for individual messages only)
  2. put it into the client (if you do this, all messages your bot sends will ping nobody by default) ╚ Example
const client = new Discord.Client({
    allowedMentions: { parse: [] }
});

Example taken from: https://github.com/discordextremelist/website/blob/5394fcd179d5fc75e0ef9fbb9e674186a13f620a/src/Util/Services/discord.ts#L30

Other libs: rd?tag allowed_mentions2 If your lib is not listed - I'm sorry, I don't know how to use it.

Discord docs: https://discord.com/developers/docs/resources/channel#allowed-mentions-object

@Lumiobyte
Copy link

No way you were the first search result when I search "how to use AllowedMentions" lol

@TheMoksej
Copy link

lol I hope we could help

@DuckMasterAl
Copy link
Author

The only other result (other than the Turkish version) is the dpy manager lol

@unknown123456789149
Copy link

how do you allow ALL mentions from ALL messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment