Give out XP when someone succesfully bumps server

Hi! So i want to give users XP when they bump the server. I atm got this (ids hardcoreds to test, where msg id is an "Bump done! 👍"message):
const guild = await client.guilds.fetch('1350811442856726559');
const channel = await guild.channels.fetch('1350813813842116619');
// @ts-ignore
const message = await channel.messages.fetch('1414934803337449562');
console.log(message.mentions)
const bumpedUserId = message.mentions.users.first();

if (!bumpedUserId) return;

console.log(`User <@${bumpedUserId}> bumped`);
const guild = await client.guilds.fetch('1350811442856726559');
const channel = await guild.channels.fetch('1350813813842116619');
// @ts-ignore
const message = await channel.messages.fetch('1414934803337449562');
console.log(message.mentions)
const bumpedUserId = message.mentions.users.first();

if (!bumpedUserId) return;

console.log(`User <@${bumpedUserId}> bumped`);
Tho the message.mentions.users gives undefined. How can i do this?
6 Replies
d.js toolkit
d.js toolkit5w ago
HeapReaper
HeapReaperOP5w ago
DiscordJS version: -- discord.js@14.22.1 NodeJS version: v22.18.0 tho using Bun
Spctr
Spctr5w ago
mm.. maybe with this
client.on('messageCreate', async (message) => {
if (message.type === 20) { // Application Command
const user = message.interaction?.user;

if (user) {
console.log(user);
}
}
});
client.on('messageCreate', async (message) => {
if (message.type === 20) { // Application Command
const user = message.interaction?.user;

if (user) {
console.log(user);
}
}
});
with this you can check for command messages and get the user
Shizuka
Shizuka4w ago
Aside from your question, you're hitting the API too often with the current implementation. You can get rate-limited quickly. You're supposed to check the cache first before using .fetch(). Make sure you do that whenever possible. Do this. Events give most of the necessary data you need at once, and populate the cache.
duck
duck4w ago
just a couple notes 1. first directed to @Shizuka, most (I believe all, but not totally sure) <Manager>.fetch(<id>) calls check the cache first for you, so you don't actually need to do that yourself 2. on top of that I believe they only had those fetches for testing purposes and in production they would already be using the message from messageCreate 3. directed towards @HeapReaper, if it wasn't clear you'd likely want to do more than just check if a message is an application command response, so in case it's relevant, you may just be missing the MessageContent intent if you're seeing a mention, and you mean that message.mentions.users.first() gives undefined, this could be the reason this would also be necessary to check <Message>.content for the format of the message you're looking to detect 4. also instead of using a magic number and commenting // Application Command after, you could always consider using the MessageType enum (more specifically MessageType.ChatInputCommand)
Shizuka
Shizuka4w ago
That is good to know

Did you find this page helpful?