Ask coding questions

← Back to all posts
Discord bot not working
[deleted]

I was making a discord bot and when someone was kicked or banned, I wanted it to say:lol someone got kicked or banned, using this code:

client.on('guildMemberRemove', msg => {
  msg.reply('lol a member was kicked or banned');
});

And instead I get an error saying that msg.reply is not a function. Why is it doing that? And ignore all the event listeners in the repl lol

Answered by Coder100 (10809) [earned 5 cycles]
View Answer
Commentshotnewtop
Coder100 (10809)

Because client.on('guildMemberRemove' does not have an argument called msg!! It has an argument on the member that is removed, but it doesn't have a message argument >:(

[deleted]

@Coder100 I know, but why dosent this code work?

client.on('guildMemberRemove', msg => {
  msg.reply('lol a member was kicked or banned');
});

It seems perfectly fine to me

Coder100 (10809)

what channel would it even send it to? @CarlosRosiles

Coder100 (10809)

a member was kicked, in what way does a discord channel or a message even have to do with that? @CarlosRosiles

[deleted]

@Coder100 #general I think

Coder100 (10809)

do you need to read the docs :/
https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-guildMemberRemove

Literally long story short: when a member gets kicked/banned, it only gives you the member that got banned and which guild it was, because nobody is going to give you some arbitrary channel, you find that yourself
@CarlosRosiles

Coder100 (10809)

ok try this code:

client.on('guildMemberRemove', member => {
  let channel = member.guild.channels.cache.find(channel => channel.name == "general").id;
  channel.send("lol a member was kicked or banned");
});

Also why are you even using msg.reply wtf

anyways this find the arbitrary channel general and sends a message.