fix(bot): update discord.js to 13, ignore non-direct mentions

This commit is contained in:
41666 2022-01-22 18:49:10 -05:00
parent cba0d1f35a
commit 7a52653260
2 changed files with 10 additions and 8 deletions

View file

@ -1,4 +1,4 @@
const { Client } = require('discord.js'); const { Client, Message } = require('discord.js');
const botToken = process.env['BOT_TOKEN']; const botToken = process.env['BOT_TOKEN'];
const allowedBots = process.env['ALLOWED_BOTS']?.split(',') ?? []; const allowedBots = process.env['ALLOWED_BOTS']?.split(',') ?? [];
@ -10,7 +10,11 @@ function messageEventListener(message) {
if (!guild) { if (!guild) {
return; return;
} // Ignore DMs } // Ignore DMs
if (client.user && !mentions.has(client.user.id)) {
if (
client.user &&
!mentions.has(client.user.id, { ignoreRoles: true, ignoreEveryone: true })
) {
return; return;
} // Ignore non bot mentions } // Ignore non bot mentions
@ -19,14 +23,12 @@ function messageEventListener(message) {
} // Only respond to allowed bots } // Only respond to allowed bots
const guildId = guild.id; const guildId = guild.id;
channel.send(`:beginner: Assign your roles here! ${appUrl}/s/${guildId}`); channel.send({ content: `:beginner: Assign your roles here! ${appUrl}/s/${guildId}` });
} }
const client = new Client({ const client = new Client({
ws: { intents: ['GUILDS', 'GUILD_MESSAGES'],
intents: ['GUILDS', 'GUILD_MESSAGES'],
},
}); });
client.on('message', (message) => messageEventListener(message)); client.on('messageCreate', (message) => messageEventListener(message));
client.login(botToken); client.login(botToken);

View file

@ -5,7 +5,7 @@
"start": "node index.js" "start": "node index.js"
}, },
"dependencies": { "dependencies": {
"discord.js": "^12.5.3", "discord.js": "^13.6.0",
"dotenv": "^10.0.0" "dotenv": "^10.0.0"
} }
} }