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