Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda