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.
CodePudding user response:
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();
}
});
CodePudding user response:
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();
}
}
});