From 0640f5ff40d98eab640cc279c4af83eec1f7b910 Mon Sep 17 00:00:00 2001 From: Waren Gonzaga Date: Wed, 8 May 2024 03:17:46 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20tweak:=20move=20message=20responder?= =?UTF-8?q?=20to=20message=20event=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bot.js | 16 ---------------- src/events/message.js | 29 ++++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/bot.js b/src/bot.js index 054a644..3db317e 100644 --- a/src/bot.js +++ b/src/bot.js @@ -112,22 +112,6 @@ client.on("messageCreate", async (message) => { } } - // get the details from user who send command - const member = message.member; - const mention = message.mentions; - - // check if the message has mentioned a team member and not a reply - if (mention.users.first() && !message.reference) { - let mentioned = message.guild.members.cache.get(mention.users.first().id) - if (mentioned.roles.cache.hasAny(...roleIDs) && !member.roles.cache.hasAny(...roleIDs)) { - message.reply({ - embeds: [sendEmbedMessage(`We have moved to a community driven discord support model.\n\nYou can ask me all things thirdweb in the <#${ASKAI_CHANNEL}> channel. Use the command \`!askai\` or \`!ask\` followed by your question to get started.`)], - }).then(msg => { - setTimeout(() => msg.delete(), 60000) - }) - } - } - }); //listen to button clicks diff --git a/src/events/message.js b/src/events/message.js index cb40d38..657fbe2 100644 --- a/src/events/message.js +++ b/src/events/message.js @@ -1,4 +1,4 @@ -const { Client, Events } = require("discord.js"); +const { Client, Events, GatewayIntentBits, Partials } = require("discord.js"); const { sendEmbedMessage, serverTime } = require("../utils/core"); const { version } = require("../../package.json"); @@ -12,15 +12,18 @@ const client = new Client({ partials: [Partials.Channel, Partials.Message], }); +// discord bot env +const { + DISCORD_SUPPORT_ROLE_ID, + ASKAI_CHANNEL +} = process.env; +const roleIDs = DISCORD_SUPPORT_ROLE_ID.split(","); + module.exports = { name: Events.MessageCreate, once: false, execute(message) { - // get the details from user who send command - const member = message.member; - const mention = message.mentions; - // prevent someone from sending DM to the bot. if (message.author.bot) return; @@ -55,5 +58,21 @@ module.exports = { }); } + // get the details from user who send command + const member = message.member; + const mention = message.mentions; + + // check if the message has mentioned a team member and not a reply + if (mention.users.first() && !message.reference) { + let mentioned = message.guild.members.cache.get(mention.users.first().id) + if (mentioned.roles.cache.hasAny(...roleIDs) && !member.roles.cache.hasAny(...roleIDs)) { + message.reply({ + embeds: [sendEmbedMessage(`We have moved to a community driven discord support model.\n\nYou can ask me all things thirdweb in the <#${ASKAI_CHANNEL}> channel. Use the command \`!askai\` or \`!ask\` followed by your question to get started.`)], + }).then(msg => { + setTimeout(() => msg.delete(), 60000) + }) + } + } + }, }; \ No newline at end of file