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•16mo 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•16mo ago
your option is giving you user not userId you dont need to find user
Sourceae
SourceaeOP•16mo ago
GuildMemberRemove need a member not a user right ?
@flexyz
@flexyz•16mo ago
do you have a error
Sourceae
SourceaeOP•16mo 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•16mo ago
GuildModeration maybe is its replying
Sourceae
SourceaeOP•16mo ago
Yes
@flexyz
@flexyz•16mo ago
logging to console? in your event file
Sourceae
SourceaeOP•16mo ago
No it's not, so the event is not emmited actually or not caught 😮
@flexyz
@flexyz•16mo ago
use trycatch in emitting
Sourceae
SourceaeOP•16mo 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•16mo ago
try { //emit } catch(err) { console.log(err) }
Sourceae
SourceaeOP•16mo ago
no log
@flexyz
@flexyz•16mo ago
are you sure your memberremove event works when someone left normally
Sourceae
SourceaeOP•16mo ago
Ill try it works : User InfluenceEvent left the guild.
@flexyz
@flexyz•16mo ago
oh, in your emit
Sourceae
SourceaeOP•16mo ago
stress I'm confused
Lorenz
Lorenz•16mo ago
Did you try fetching members before finding
Sourceae
SourceaeOP•16mo ago
It works I fetch all members on ready
Lorenz
Lorenz•16mo ago
HmCat
Sourceae
SourceaeOP•16mo ago
i just misspelled guildMemberRemove
Lorenz
Lorenz•16mo ago
bruh, okay solved then
Sourceae
SourceaeOP•16mo ago
EHEHBOY guys
Want results from more Discord servers?
Add your server