Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
Discord.js: ban user that reacted to a message with emoji

I am working on a discord bot who is supposed to ban members that reacted to a specific message with a specific emote. The file I created for the messageReactionAdd event currently contains the following code:

module.exports = {
    name: 'messageReactionAdd',
    execute(client, reaction, user) {
        const channel = client.channels.cache.find(channel => channel.name === 'test');
        let message = 874736592542105640;
        let emotes = ['kannathinking', '๐ŸŽ'];
        let roleID = (reaction.emoji.name == emotes[0] ? '874730080486686730' : '874729987310235738')

        if (message == reaction.message.id && (emotes[0] == reaction.emoji.name || emotes[1] == reaction.emoji.name)) {
        user.ban();
        channel.send(`${user} was banned`);
        }
    }
}

However this code doesn't work and throws me the following error:

user.ban() is not a function

After doing some research I found out that the ba command only works on GuildMember objects. Unfortunately those aren't created when messageReactionAdd is called. Does anyone have an idea how to work around it?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

You don't have to get the GuildMember object, you can just ban the user by id from GuildMemberManager which can be found from the reaction object via reaction.message.guild.members

So instead of using user.ban() you can use

reaction.message.guild.members.ban(user.id)
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!