'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 }));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
