blacklist system not working

const { model, Schema } = require('mongoose');

let blacklist = new Schema({
User: String
});

module.exports = model('blacklist', blacklist);
const { model, Schema } = require('mongoose');

let blacklist = new Schema({
User: String
});

module.exports = model('blacklist', blacklist);
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const blacklist = require('../../models/blacklist');

module.exports = {
data: new SlashCommandBuilder()
.setName('blacklist')
.setDescription('Blacklist a user from using this bot')
.addSubcommand(command => command
.setName('add')
.setDescription('Add a user to the blacklist')
.addStringOption(option => option
.setName('user')
.setDescription('The user ID you want to blacklist')
.setRequired(true)
)
)
.addSubcommand(command => command
.setName('remove')
.setDescription('Remove a user from the blacklist')
.addStringOption(option => option
.setName('user')
.setDescription('The user ID you want to remove from the blacklist')
.setRequired(true)
)
),
async execute(interaction) {

const { options } = interaction;
if(interaction.user.id !== '778992675830759455') return await interaction.reply({ content: `Only cyukizzz can use this command!`, ephemeral: true });

const user = options.getString('user');
const data = await blacklist.findOne({ User: user });
const sub = options.getSubcommand();

switch(sub) {
case 'add':

if(!data) {
await blacklist.create({
User: user,
})



const embed = new EmbedBuilder()
.setColor('Red)
.setDescription(` \`${user}\` has been blacklisted from using my commands.`)
.setTimestamp()

await interaction.reply({ embeds: [embed] });
} else if(data) {
return await interaction.reply({ content: `The user \`${user}\` has already been **blacklisted**`, ephemeral: true })
}

break;
case 'remove':
if(!data) {
return await interaction.reply({ content: `The user \`${user}\` is not on the **blacklist**`, ephemeral: true })
} else if(data) {
await blacklist.deleteMany({ User: user });

const embed = new EmbedBuilder()
.setColor('Green')
.setDescription(`\`${user}\` has been removed from the blacklist.`)
.setTimestamp()

await interaction.reply({ embeds: [embed], ephemeral: true });
}
}
}
}
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const blacklist = require('../../models/blacklist');

module.exports = {
data: new SlashCommandBuilder()
.setName('blacklist')
.setDescription('Blacklist a user from using this bot')
.addSubcommand(command => command
.setName('add')
.setDescription('Add a user to the blacklist')
.addStringOption(option => option
.setName('user')
.setDescription('The user ID you want to blacklist')
.setRequired(true)
)
)
.addSubcommand(command => command
.setName('remove')
.setDescription('Remove a user from the blacklist')
.addStringOption(option => option
.setName('user')
.setDescription('The user ID you want to remove from the blacklist')
.setRequired(true)
)
),
async execute(interaction) {

const { options } = interaction;
if(interaction.user.id !== '778992675830759455') return await interaction.reply({ content: `Only cyukizzz can use this command!`, ephemeral: true });

const user = options.getString('user');
const data = await blacklist.findOne({ User: user });
const sub = options.getSubcommand();

switch(sub) {
case 'add':

if(!data) {
await blacklist.create({
User: user,
})



const embed = new EmbedBuilder()
.setColor('Red)
.setDescription(` \`${user}\` has been blacklisted from using my commands.`)
.setTimestamp()

await interaction.reply({ embeds: [embed] });
} else if(data) {
return await interaction.reply({ content: `The user \`${user}\` has already been **blacklisted**`, ephemeral: true })
}

break;
case 'remove':
if(!data) {
return await interaction.reply({ content: `The user \`${user}\` is not on the **blacklist**`, ephemeral: true })
} else if(data) {
await blacklist.deleteMany({ User: user });

const embed = new EmbedBuilder()
.setColor('Green')
.setDescription(`\`${user}\` has been removed from the blacklist.`)
.setTimestamp()

await interaction.reply({ embeds: [embed], ephemeral: true });
}
}
}
}
client.on(Events.InteractionCreate, async interaction => {
const blacklist = require('./models/blacklist');
const data = await blacklist.findOne({ User: interaction.user.id });

if(data) {
return await interaction.reply({ content: `You have been **blacklisted** from using this bot! This means the developer doesn't want you to use it's commands for any given reason`, ephemeral: true })
}

if (!data)
return;
})
client.on(Events.InteractionCreate, async interaction => {
const blacklist = require('./models/blacklist');
const data = await blacklist.findOne({ User: interaction.user.id });

if(data) {
return await interaction.reply({ content: `You have been **blacklisted** from using this bot! This means the developer doesn't want you to use it's commands for any given reason`, ephemeral: true })
}

if (!data)
return;
})
it says the user is blacklisted but the commands are still running for them
20 Replies
d.js toolkit
d.js toolkit15mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Honorificabilitudinity
add another quote.
keekztah
keekztah15mo ago
thats not the issue, i deleted it on acciden twhen i was sending the code here.
Honorificabilitudinity
😭 ik im looking at it rn
keekztah
keekztah15mo ago
theres no error, it just doesnt blacklist the user so somethings wrong with the event.
Honorificabilitudinity
well you didnt add any checks in the actual command async function to check if a player is blacklisted.
keekztah
keekztah15mo ago
keekztah
keekztah15mo ago
its right there
Honorificabilitudinity
how are you actually creating the commands you are using rest routes so interactionEvent wouldnt work
keekztah
keekztah15mo ago
and like i said it works, the person gets added to the schema on mongodb. so the only thing not working is the fact that the person can still run the command.
Honorificabilitudinity
correct... the issue is that you have a check in a useless spot.
keekztah
keekztah15mo ago
ok
Honorificabilitudinity
you are using REST put to create the command correct?
keekztah
keekztah15mo ago
yep
Want results from more Discord servers?
Add your server