Emit command not emitting the event

Hello I'm making an 'Emit' command in order to test some event handlers. Here's my code :
// emit.js
data: new SlashCommandBuilder()
.setName('emit')
.setDescription('[DEV] Emit discord events for testing purposes')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The usser to remove')
.setRequired(true)
),

async execute(interaction) {
const userId = interaction.options.getUser('user').id;
const memberToRemove = interaction.guild.members.cache.find(
(member) => member.user.id === userId
);

interaction.client.emit('GuildMemberRemove', memberToRemove);
await interaction.reply('GuildMemberRemove event emitted successfully.');
},
// emit.js
data: new SlashCommandBuilder()
.setName('emit')
.setDescription('[DEV] Emit discord events for testing purposes')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The usser to remove')
.setRequired(true)
),

async execute(interaction) {
const userId = interaction.options.getUser('user').id;
const memberToRemove = interaction.guild.members.cache.find(
(member) => member.user.id === userId
);

interaction.client.emit('GuildMemberRemove', memberToRemove);
await interaction.reply('GuildMemberRemove event emitted successfully.');
},
// guildMemberRemove.js
name: Events.GuildMemberRemove,
async execute(member) {
console.log(`${member.user.username} left the guild.`
}
// guildMemberRemove.js
name: Events.GuildMemberRemove,
async execute(member) {
console.log(`${member.user.username} left the guild.`
}
The event is not triggered when I execute my command. Any idea please ?
23 Replies
d.js toolkit
d.js toolkit•11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
@flexyz
@flexyz•11mo ago
your option is giving you user not userId you dont need to find user
Sourceae
Sourceae•11mo ago
GuildMemberRemove need a member not a user right ?
@flexyz
@flexyz•11mo ago
do you have a error
Sourceae
Sourceae•11mo ago
No error I'll log memberToRemove a sec memberToRemove is working great, I have a GuildMember object do I need any specific intent on my client for emitting events ?
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
partials: [Partials.GuildMembers],
});
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
partials: [Partials.GuildMembers],
});
@flexyz
@flexyz•11mo ago
GuildModeration maybe is its replying
Sourceae
Sourceae•11mo ago
Yes
@flexyz
@flexyz•11mo ago
logging to console? in your event file
Sourceae
Sourceae•11mo ago
No it's not, so the event is not emmited actually or not caught 😮
@flexyz
@flexyz•11mo ago
use trycatch in emitting
Sourceae
Sourceae•11mo ago
try {
interaction.client.emit('GuildMemberRemove', memberToRemove);
} catch (error) {
console.log(error);
}
try {
interaction.client.emit('GuildMemberRemove', memberToRemove);
} catch (error) {
console.log(error);
}
@flexyz
@flexyz•11mo ago
try { //emit } catch(err) { console.log(err) }
Sourceae
Sourceae•11mo ago
no log
@flexyz
@flexyz•11mo ago
are you sure your memberremove event works when someone left normally
Sourceae
Sourceae•11mo ago
Ill try it works : User InfluenceEvent left the guild.
@flexyz
@flexyz•11mo ago
oh, in your emit
Sourceae
Sourceae•11mo ago
stress I'm confused
Lorenz
Lorenz•11mo ago
Did you try fetching members before finding
Sourceae
Sourceae•11mo ago
It works I fetch all members on ready
Lorenz
Lorenz•11mo ago
HmCat
Sourceae
Sourceae•11mo ago
i just misspelled guildMemberRemove
Lorenz
Lorenz•11mo ago
bruh, okay solved then
Sourceae
Sourceae•11mo ago
EHEHBOY guys