New slash commands not registering

Two of my slash commands (new ones, created after the last deployment) are not being registered. I checked that the array I use for the deployment does include them, yet they are still not being registered. Example code of one of the slash command files
const config = require('../config.json');
const mongoose = require('mongoose');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setName("unmute")
.setDescription("הסרת מיוט")
.addUserOption(option =>
option
.setName("user")
.setDescription("המשתמש")
.setRequired(true)
)
,
async execute(interaction, client) {
const member = interaction.options.getMemberOption("user");

const role = interaction.guild.roles.cache.get(config.muteRole);

if (!member)
return interaction.reply("משתמש זה אינו נמצא בשרת");

if (!member.roles.cache.some(r => r.id === role.id)) return interaction.reply({ephemeral: true, content: "למשתמש זה אין מיוט פעיל"});
member.roles.remove(role);

const Embed = new EmbedBuilder()
.setTitle("נתינת מיוט על ידי חבר צוות")
.setColor(0x32FF32)
.setTimestamp()
.addFields(
{name: "מסיר:", value: `${interaction.user}`},
{name: "מקבל:", value: `${member}`}
)

interaction.reply("המיוט ניתן בהצלחה");
interaction.guild.channels.cache.get(config.mutesRoom).send({embeds: [Embed]})
},
};
const config = require('../config.json');
const mongoose = require('mongoose');
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.setName("unmute")
.setDescription("הסרת מיוט")
.addUserOption(option =>
option
.setName("user")
.setDescription("המשתמש")
.setRequired(true)
)
,
async execute(interaction, client) {
const member = interaction.options.getMemberOption("user");

const role = interaction.guild.roles.cache.get(config.muteRole);

if (!member)
return interaction.reply("משתמש זה אינו נמצא בשרת");

if (!member.roles.cache.some(r => r.id === role.id)) return interaction.reply({ephemeral: true, content: "למשתמש זה אין מיוט פעיל"});
member.roles.remove(role);

const Embed = new EmbedBuilder()
.setTitle("נתינת מיוט על ידי חבר צוות")
.setColor(0x32FF32)
.setTimestamp()
.addFields(
{name: "מסיר:", value: `${interaction.user}`},
{name: "מקבל:", value: `${member}`}
)

interaction.reply("המיוט ניתן בהצלחה");
interaction.guild.channels.cache.get(config.mutesRoom).send({embeds: [Embed]})
},
};
Code for the deployment:
let slashCommands = [];
client.slashCommands = new Discord.Collection();
const slashCommandFiles = fs.readdirSync('./slashCommands');
for (const file of slashCommandFiles) {
if (!file.endsWith(".js")) continue;
const command = require(`../slashCommands/${file}`);
client.slashCommands.set(command.data.name, command);
slashCommands.push(command.data);
}
try {
console.log(slashCommands);
await rest.put(Routes.applicationGuildCommands(config.botID, config.guildID), { body: slashCommands});
console.log("application commands refreshed")
} catch(error) {console.log(error)}
let slashCommands = [];
client.slashCommands = new Discord.Collection();
const slashCommandFiles = fs.readdirSync('./slashCommands');
for (const file of slashCommandFiles) {
if (!file.endsWith(".js")) continue;
const command = require(`../slashCommands/${file}`);
client.slashCommands.set(command.data.name, command);
slashCommands.push(command.data);
}
try {
console.log(slashCommands);
await rest.put(Routes.applicationGuildCommands(config.botID, config.guildID), { body: slashCommands});
console.log("application commands refreshed")
} catch(error) {console.log(error)}
7 Replies
d.js toolkit
d.js toolkit2y 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. - Issue solved? Press the button!
DanielBA
DanielBAOP2y ago
Yes, and I do have administrator permissions in it
It's Manny
It's Manny2y ago
I don't know much about the rest api but you could try guild.commands.set()
DanielBA
DanielBAOP2y ago
Forgot to update you, around an hour ago it fixed itself I changed nothing in the code
It's Manny
It's Manny2y ago
Oh ok sweet
DanielBA
DanielBAOP2y ago
Not sure what happened there
It's Manny
It's Manny2y ago
Must've just taken awhile to load

Did you find this page helpful?