- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
#Token Invalid but Already put correct token
17 messages · Page 1 of 1 (latest)
Sounds like your code might not actually load the secret correctly
Without seeing your code that’s a question impossible to answer
its long so i split it
const express = require("express");
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("fs");
// Express Server Setup
const app = express();
app.get("/", (_, res) => res.send("Bot is running!"));
app.listen(3000, () => console.log("Web server running!"));
// Discord Client Setup
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
// Collections
client.commands = new Collection();
client.slashCommands = new Collection();
const slashCommands = [];
// Load Regular Commands
const commandFiles = fs
.readdirSync("./Commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./Commands/${file}`);
client.commands.set(command.name, command);
}
// Load Slash Commands
const slashFiles = fs
.readdirSync("./SlashCommands")
.filter((file) => file.endsWith(".js"));
for (const file of slashFiles) {
const command = require(`./SlashCommands/${file}`);
client.slashCommands.set(command.data.name, command);
slashCommands.push(command.data.toJSON());
}
// Message Command Handler
client.on("messageCreate", async (message) => {
if (message.author.bot || !message.content.startsWith("./")) return;
const args = message.content.slice(2).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName);
if (!command) return;```
try {
await command.run(client, message, args);
} catch (error) {
console.error(error);
message.reply("There was an error executing that command!");
}
});
// Slash Command Handler
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
const command = client.slashCommands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error executing this command!",
ephemeral: true,
});
}
});
// Ready Event
client.once("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity("with commands | ./help", { type: "PLAYING" });
});
// Debug token loading
const token = process.env.token;
console.log('Token exists:', !!token);
console.log('Token length:', token ? token.length : 0);
if (!token) {
console.error('Bot token not found in environment variables!');
process.exit(1);
}
client.login(token);```
here, i hope it easier to solve it 🙂
And what do those two console logs log?
Since they don’t seem to exist in your console here
I also don't see dotenv in your require list. How are you passing your experiment variables to node?
i use secrets tab
Yup, you did say you're using Replit...that makes sense, it's 3am, I shouldn't be debugging other people's code
uh, sorry to disturb you then..
No, my fault not yours