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

94
Views
Discord blacklist with JSON file

I want to make a blacklist user.id with a json file, when they are using a command, it will send if they're blacklisted or not and if they're blacklisted, it will send the reason

I try this code:

const discord = require('discord.js');
const client = new discord.Client();
const prefix = '+';
const token = 'my bot token';
const blacklist = require('./blacklist.json');

client.on('ready', function () {
  console.log('bot on');
});

client.on('message', function (message) {
  if (message.content.startsWith(prefix + 'check')) {
    if (blacklist.includes(client.user.id)) {
      message.channel.send('you are blacklist, reason: ${reason}');
    } else {
      message.channel.send('heyy');
    }
  }
});

client.login(token);

The JSON file:

{
  "user.id1": "reason",
  "user.id2": "reason"
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If the object keys in your JSON file are user IDs, you can use bracket notation to check if the object contains a key, like this:

if (blacklist[user.id]) {
  // user.id exists on blacklist
}

Also, I don't think you want to check the client.user.id; that's the logged-in client's Discord user. You probably want to check the user who sent the messsage/command, so message.author. The following code should work:

client.on('message', function (message) {
  if (!message.content.startsWith(prefix + 'check')) return;

  if (blacklist[message.author.id])
    return message.channel.send(
      `You are on the blacklist, reason: ${blacklist[message.author.id]}`
    );

  message.channel.send('heyy');
});
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!