#Token Invalid but Already put correct token

17 messages · Page 1 of 1 (latest)

quiet barnBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • 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!
junior tendon
#

Sounds like your code might not actually load the secret correctly

deep goblet
#

oh, so how do i fix it?

#

this is the console

junior tendon
#

Without seeing your code that’s a question impossible to answer

deep goblet
#

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 🙂

junior tendon
#

And what do those two console logs log?

junior tendon
past orbit
#

I also don't see dotenv in your require list. How are you passing your experiment variables to node?

past orbit
#

Yup, you did say you're using Replit...that makes sense, it's 3am, I shouldn't be debugging other people's code

deep goblet
past orbit
#

No, my fault not yours