Ryan
Ryan
DIAdiscord.js - Imagine an app
Created by Ryan on 2/4/2024 in #djs-questions
Slash command setting not working
Trying to set slash commands for my bot and I'm not getting any errors, but my slash commands are not being updated properly. I'm using DJS 14.14.1. Am I doing something wrong?
require('dotenv').config();
const fs = require('fs');
const { Client, GatewayIntentBits, PermissionsBitField } = require('discord.js');
const { Logger, Level } = require('./util/logger.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// Initialize commands
const commands = new Map();

// Builds the list of commands to set
const commandList = [];

const commandPaths = fs.readdirSync('./commands');
for(const commandPath of commandPaths) {
const command = require(`./commands/${ commandPath }`);
commandList.push({
name: command.name,
description: command.description,
options: command.options,
defaultMemberPermissions: PermissionsBitField.Default
});
commands.set(command.name, command.obj);
Logger.log(Level.INFO, `Command initialized successfully: ${ command.name }`);
}

client.on('ready', async () => {
// Set the commands for the bot
console.log(await client.application.commands.set(commandList));
Logger.log(Level.INFO, 'Commands successfully sent to Discord.');

Logger.log(Level.INFO, 'Bot started successfully!');
});
require('dotenv').config();
const fs = require('fs');
const { Client, GatewayIntentBits, PermissionsBitField } = require('discord.js');
const { Logger, Level } = require('./util/logger.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// Initialize commands
const commands = new Map();

// Builds the list of commands to set
const commandList = [];

const commandPaths = fs.readdirSync('./commands');
for(const commandPath of commandPaths) {
const command = require(`./commands/${ commandPath }`);
commandList.push({
name: command.name,
description: command.description,
options: command.options,
defaultMemberPermissions: PermissionsBitField.Default
});
commands.set(command.name, command.obj);
Logger.log(Level.INFO, `Command initialized successfully: ${ command.name }`);
}

client.on('ready', async () => {
// Set the commands for the bot
console.log(await client.application.commands.set(commandList));
Logger.log(Level.INFO, 'Commands successfully sent to Discord.');

Logger.log(Level.INFO, 'Bot started successfully!');
});
21 replies