'When a user mentions the owner the bot should say you're not allowed
I am trying to make it when a user is tagged (eg. MyNameJeff#0001), the bot will automatically respond with you're not allowed to mention them and delete their message.
I tried searching for an event that could handle this but haven't found anything useful so far.
Solution 1:[1]
You can check if the collection message.mentions.users includes the guild owner's ID with the has() method. A simple if (message.mentions.users.has(message.guild.ownerId)) will work for you:
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.mentions.users.has(message.guild.ownerId)) {
message.channel.send('You are not allowed to mention the owner!');
message.delete();
}
});
Solution 2:[2]
There's no special event to do what you are trying to achieve. You could just use the messageCreate event, check if there are any mentions in the message and then if there are some mentions, then check if the mentioned user was the owner of the guild. The code would look something like this:
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.mentions) { // This checks if there are any mentions in the message
if (message.mentions.users.first().id === message.guild.ownerId) { // This checks if the mentioned user was the owner of the server
message.channel.send(
"You are not allowed to mention the owner of the server!"
);
message.delete();
}
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zsolt Meszaros |
| Solution 2 | Caladan |
