Client.once("ready") never called #1273
-
I am trying to program a discord bot on Replit, but I cannot seem to get it to work well. // Require the necessary discord.js classes
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const token = process.env['token']
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
client.once('ready', () => {
console.log("Ready!");
});
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
// When the client is ready, run this code (only once)
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.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 });
}
});
// Login to Discord with your client's token
client.login(token); |
Beta Was this translation helpful? Give feedback.
Answered by
Bubalo1234
Sep 22, 2022
Replies: 3 comments 3 replies
-
You're not logging in anywhere? |
Beta Was this translation helpful? Give feedback.
3 replies
-
wait I forgot to copy the whole thing |
Beta Was this translation helpful? Give feedback.
0 replies
-
reset the token and readied it |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Bubalo1234
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reset the token and readied it