Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda