#Mr. Glitz 20220222
1 messages · Page 1 of 1 (latest)
which file
index.js
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);```
also make sure you arent possting to a specific guild
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);```
you're pushing to one guild
yes
is that intentional
thats what you should do for development anyway
prob, he didnt enabled application command scope for his bot ig
i enabled
log clientId, guildId and commands
(after your for loop)
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
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.