Bobby The Catfish
Bobby The Catfish

Reputation: 3

How to kick on specific message

I'm trying to auto-kick people with my discord bot when they send an invite link, but message.author.kick() doesn't seem to work. I've also tried other variations of it, like member.kick().

This is my code so far:

client.on('message', message => {
  if (message.content.includes('discord.gg/')) {
    message.channel.send('Nope');
    message.delete(3000);
    message.author.kick('posting links');
  }
});

Upvotes: 0

Views: 874

Answers (1)

Gilles Heinesch
Gilles Heinesch

Reputation: 2980

.author gives a User object that you can't kick. You have to kick a GuildMember: you can obtain the author's member object by using message.member.

Here is the correction of your code:

client.on('message', message => {
  if (message.content.includes('discord.gg/')) {
    message.channel.send('Nope');
    message.delete(3000);
    message.member.kick('posting links');
  }
});

Upvotes: 2

Related Questions