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