#my bot doesn't responding
6 messages · Page 1 of 1 (latest)
// IMPORT MODULE
const discord = require("discord.js");
const fs = require("node:fs");
const path = require("node:path");
require("dotenv").config();
const { Client, Intents, Routes, REST, GatewayIntentBits, Collection, ActivityType } = require("discord.js");
const { Player } = require("discord-player");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates
]
});
const config = require("./config.json");
// LOGIN BOT
const token = process.env.TOKEN;
if(!token){
console.log("The discord token is not found in .env, maybe forget to add or invalid variable name?");
process.exit();
};
client.login(token).catch(error => {
console.log("The discord token is invalid. Maybe wrong token or the token has been revoked");
process.exit();
});
// LOAD SLASH COMMAND
const commands = [];
client.commands = new Collection();
const commandPath = path.join(__dirname, "command");
const commandFiles = fs.readdirSync("./command").filter(file => file.endsWith(".js"));
if(!commandFiles) return console.log("No command found in command folder");
for(const count of commandFiles){
const filePath = path.join(commandPath, count);
const command = require(filePath);
try{
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
console.log(`✅ Loaded Command: ${command.data.name}`);
}catch(error){
};
};
// INTERACTION CREATE
client.once("interactionCreate", async(interaction) => {
if(!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if(!command) return;
try{
await command.execute(client, interaction);
}catch(error){
interaction.reply({ content:"An error occured while executing this command. Please try again later", ephemeral: true });
console.log(`New Error While Executing Command: `, error);
};
});
your interactionCreate is set to only emit once because of client.once
change that to client.on and see if that fixes it
it’s probably better that you call client.login at the bottom of your code after the event is made
oh oky lemme try