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

291
Views
How to make blacklist server commands in discord.js v12?

here i want to blacklist and whitelist the server, but when i try the command it always shows:

Script:

module.exports.run = async(client, message, args) => {
const Discord = require('discord.js');
const schema = require('../../models/guild-schema');
const { version, author } = require('../../package.json');
const ownerid = process.env.OWNER

if (message.author.id !== ownerid) return;

let guild = client.guilds.cache.get(args[0]);
if (!guild) return message.channel.send(client.em(`โ— Please specify Guild ID!`)).then(msg => msg.delete({ timeout: 6000 }));
let data;
try {
    data = await schema.findOne({
        guildId: guild.id
    })
    if(!data) {
        data = await schema.create({
            guildId: guild.id
        })
    }
} catch (err) {
    console.log(`[ERROR] ${err}`);
}

data.blacklisted = true
await data.save()

const SuccessEmbed = new Discord.MessageEmbed()
.setColor('#00ff00')
.setTitle(`โœ… Successfully blacklisted ${guild.name}!`)
.setDescription(`\`\`\`js\n${JSON.stringify(data, null, 2)}\`\`\``)
.setFooter(`Status Guilds: [ ${data.blacklisted} ] | Siesta v${version}`)

return message.channel.send(SuccessEmbed)
}

module.exports.help = {
  name: 'blacklist-guild',
  aliases: ['bl-guild', 'blguild', 'blacklistguild'],
  usage: 'blacklist-guild <guild>'
}

Console:

[ERROR] ValidationError: guilId: Path `guilId` is required.

Unhandled Rejection at: Promise: undefined reason: Promise { TypeError: Cannot set properties of null (setting 'blacklisted') at Object.module.exports.run (C:\Users\User\Desktop\Discord Chatbot Update v13\commands\๐Ÿ‘‘ Developer\blacklist-server.js:25:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5) } TypeError: Cannot set properties of null (setting 'blacklisted') at Object.module.exports.run (C:\Users\User\Desktop\Discord Chatbot Update v13\commands\๐Ÿ‘‘ Developer\blacklist-server.js:25:22) at processTicksAndRejections (node:internal/process/task_queues:96:5) undefined

and where can I fill in this script?

if (!client.guilds.cache.get(guild)) return message.channel.send(client.em(':exclamation: I am not in that server!')).then(msg => msg.delete({ timeout : 6000 }));
about 4 years ago ยท Juan Pablo Isaza
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!