I am trying to make a ban command and this error keeps popping up:
D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:47
throw this.error;
^
CombinedError: Received one or more errors
at UnionValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:1058:23)
at UnionValidator.parse (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at validateDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:877:36)
at MixedClass.setDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:1345:29)
at Object.<anonymous> (D:\projs\js\MASST\commands\ban.js:15:4)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19) {
errors: [
ValidationError: Expected undefined or null
at NullishValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:718:79)
at NullishValidator.run (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at validateDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:877:36)
at MixedClass.setDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:1345:29)
at Object.<anonymous> (D:\projs\js\MASST\commands\ban.js:15:4)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32) {
validator: 's.nullish',
given: [ 2048n, 65536n, 4n ]
},
ValidationError: Expected a bigint primitive
at BigIntValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:520:70)
at BigIntValidator.run (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at validateDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:877:36)
at MixedClass.setDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:1345:29)
at Object.<anonymous> (D:\projs\js\MASST\commands\ban.js:15:4)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32) {
validator: 's.bigint',
given: [ 2048n, 65536n, 4n ]
},
ValidationError: Expected a number primitive
at NumberValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:866:70)
at NumberValidator.run (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at validateDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:877:36)
at MixedClass.setDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:1345:29)
at Object.<anonymous> (D:\projs\js\MASST\commands\ban.js:15:4)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32) {
validator: 's.number',
given: [ 2048n, 65536n, 4n ]
},
ValidationError: Expected a string primitive
at StringValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:1672:70)
at StringValidator.run (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:99:23)
at UnionValidator.handle (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:1053:32)
at UnionValidator.parse (D:\projs\js\MASST\node_modules\@sapphire\shapeshift\dist\index.js:113:88)
at validateDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:877:36)
at MixedClass.setDefaultMemberPermissions (D:\projs\js\MASST\node_modules\@discordjs\builders\dist\index.js:1345:29)
at Object.<anonymous> (D:\projs\js\MASST\commands\ban.js:15:4)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32) {
validator: 's.string',
given: [ 2048n, 65536n, 4n ]
}
]
}
ban.js:
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const botPerms = [
PermissionFlagsBits.SendMessages,
PermissionFlagsBits.ReadMessageHistory,
PermissionFlagsBits.BanMembers,
];
module.exports = {
data: new SlashCommandBuilder()
// Command name. Example: /choices
.setName('ban')
// Command's description. Shows up in commands menu once / is typed.
.setDescription('Bans specified user')
.setDefaultMemberPermissions(botPerms)
.addUserOption(option =>
option
.setName('user')
.setDescription('User to ban.')
.setRequired(true),
)
.addStringOption(option =>
option
.setName('reason')
.setDescription('Why was the user banned?')
.setRequired(true),
),
async execute(interaction) {
if (interaction.guild.members.me.permissions.has(botPerms)) {
const user = interaction.options.getUser('user');
const reason = interaction.options.getString('reason');
if (user.bannable === true) {
interaction.guild.members.ban(user);
interaction.reply('Banned!');
try {
user.send(`You have been banned from ${interaction.guild.name}!\nReason::${reason}`);
}
catch (error) {
interaction.followUp('Failed to DM banned user.');
}
}
}
},
};
deploy-commands.js:
const { REST, Routes } = require('discord.js');
const { clientId, token } = require('./config.json');
const fs = require('node:fs');
const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(token);
// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
}
catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
What's wrong? I as well couldn't find anything about it on the internet. The logs don't really help, but I for sure know the error is caused by ban.js. No idea how though.
node deploy-commands.js
and node init.js
— both gave out same error. I am really clueless about it.
CodePudding user response:
Firstly, you are not handling your error. You'll get a nicely formatted error if you catch it... so catch it!
Moving on to the problem, .setDefaultMemberPermissions(botPerms)
is the issue. Let's explain the logs: it says it expected undefined
or null
, a bigint
, a number
or a string
. However, you gave [2048n, 65536n, 4n]
. An array, of course, is none of these. This is why you get the error.
You cannot give a list of permissions here. You should do const botPerms = PermissionFlagsBits.SendMessages | PermissionFlagsBits.ReadMessageHistory | PermissionFlagsBits.BanMembers
instead. The |
is a bitwise OR which joins the permissions together, setting the default member permissions to all of these.
Here is the relevant documentation link: https://discordjs.dev/docs/packages/builders/main/SlashCommandBuilder:Class#setDefaultMemberPermissions