Skip to content

Commit

Permalink
✨ tweak: move message responder to message event file
Browse files Browse the repository at this point in the history
  • Loading branch information
warengonzaga authored May 8, 2024
1 parent 48fb083 commit 0640f5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
16 changes: 0 additions & 16 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 24 additions & 5 deletions src/events/message.js
Original file line number Diff line number Diff line change
@@ -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");

Expand All @@ -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;

Expand Down Expand Up @@ -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)
})
}
}

},
};

0 comments on commit 0640f5f

Please sign in to comment.