#Mr. Glitz 20220222

1 messages · Page 1 of 1 (latest)

green socket
#

Paste your whole file

brazen lantern
compact plume
#

index.js

brazen lantern
#
const { Client, Collection, Intents } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.data.name, command);
}

client.once('ready', () => {
    console.log('Ready!');
});

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    const command = client.commands.get(interaction.commandName);

    if (!command) return;

    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
    }
});



client.login(token);```
compact plume
#

also make sure you arent possting to a specific guild

errant prawn
#

show the code that registers the commands

compact plume
#

nvm show your file

#

that shows cmd register

brazen lantern
# errant prawn show the code that registers the commands
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    commands.push(command.data.toJSON());
}

const rest = new REST({ version: '9' }).setToken(token);

rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
    .then(() => console.log('Successfully registered application commands.'))
    .catch(console.error);```
compact plume
#

you're pushing to one guild

brazen lantern
compact plume
#

is that intentional

errant prawn
#

thats what you should do for development anyway

chilly star
#

prob, he didnt enabled application command scope for his bot ig

errant prawn
#

(after your for loop)

compact plume
#

i just read through earlier chat, and i believe theres a good possibility he entered the wrong guildId or is attempting to use the bot in a guild where the commands arent registered

green socket
#

The process should be:
Bot is Ready
Register your Commands (using ClientId, and GuildId for development) - (preferably not within client.on('ready'))
Try and use your Commands

If the commands to not appear, they must not have registered due to another reason, such as above bot lacking some perms or invited without bot commands enabled, etc.