token error

he umm everything is working fine until all i did was add a comment and then it says token invalid
15 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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! - Marked as resolved by OP
chess_legend
chess_legendOP10mo ago
Error [TokenInvalid]: An invalid token was provided. at Client.login (C:\Users\aavig\python\discord-bot\node_modules\discord.js\src\client\Client.js:216:52) at Object.<anonymous> (C:\Users\aavig\python\discord-bot\src\index.js:37:8) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) at node:internal/main/run_main_module:28:49 { code: 'TokenInvalid' } [email protected] v20.11.1
Harnes
Harnes10mo ago
Show your code
chess_legend
chess_legendOP10mo ago
require('dotenv').config();
const { Client, IntentsBitField, Message } = require('discord.js');

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on('ready', (c) => {
console.log(`✅ ${c.user.tag} is online.`);
});
client.on("messageCreate",(message)=> {
if (message.content === "hello"){
message.reply("hey")
}
})




client.on('interactionCreate', (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'hey') {
return interaction.reply('hey!');
}

if (interaction.commandName === 'ping') {
return interaction.reply('Pong!');
}
});

client.login(process.env.TOKEN);
require('dotenv').config();
const { Client, IntentsBitField, Message } = require('discord.js');

const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});

client.on('ready', (c) => {
console.log(`✅ ${c.user.tag} is online.`);
});
client.on("messageCreate",(message)=> {
if (message.content === "hello"){
message.reply("hey")
}
})




client.on('interactionCreate', (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'hey') {
return interaction.reply('hey!');
}

if (interaction.commandName === 'ping') {
return interaction.reply('Pong!');
}
});

client.login(process.env.TOKEN);
this is pacage.json
{
"name": "python",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^14.14.1",
"dotenv": "^16.4.5"
}
}
{
"name": "python",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^14.14.1",
"dotenv": "^16.4.5"
}
}
require('dotenv').config();
const { REST, Routes } = require('discord.js');

const commands = [
{
name: 'hey',
description: 'Replies with hey!',
},
{
name: 'ping',
description: 'Pong!',
},
];

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

(async () => {
try {
console.log('Registering slash commands...');

await rest.put(
Routes.applicationGuildCommands(
'93923929320913912',
'399291293199129219'
),
{ body: commands }
);

console.log('Slash commands were registered successfully!');
} catch (error) {
console.log(`There was an error: ${error}`);
}
})();
require('dotenv').config();
const { REST, Routes } = require('discord.js');

const commands = [
{
name: 'hey',
description: 'Replies with hey!',
},
{
name: 'ping',
description: 'Pong!',
},
];

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

(async () => {
try {
console.log('Registering slash commands...');

await rest.put(
Routes.applicationGuildCommands(
'93923929320913912',
'399291293199129219'
),
{ body: commands }
);

console.log('Slash commands were registered successfully!');
} catch (error) {
console.log(`There was an error: ${error}`);
}
})();
ahmood
ahmood10mo ago
Are you sure .env has the correct token
chess_legend
chess_legendOP10mo ago
positive
ahmood
ahmood10mo ago
Try regenerating the token
chess_legend
chess_legendOP10mo ago
i did just now is it not detecting the change i did control save
ahmood
ahmood10mo ago
You have to put the new token in the .env file
chess_legend
chess_legendOP10mo ago
i did
chess_legend
chess_legendOP10mo ago
No description
ahmood
ahmood10mo ago
Log process.env and see if it's there
chess_legend
chess_legendOP10mo ago
i just got things like my computer name and aapdata and stuff i dont see the token like this right? require('dotenv').config(); console.log(process.env) const { Client, IntentsBitField, Message } = require('discord.js'); const client = new Client({ intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.MessageContent, ], }); client.on('ready', (c) => { console.log(✅ ${c.user.tag} is online.); }); client.on("messageCreate",(message)=> { if (message.content === "hello"){ message.reply("hey") } }) client.on('interactionCreate', (interaction) => { if (!interaction.isChatInputCommand()) return; if (interaction.commandName === 'hey') { return interaction.reply('hey!'); } if (interaction.commandName === 'ping') { return interaction.reply('Pong!'); } }); client.login(process.env.TOKEN);
ahmood
ahmood10mo ago
Maybe put the.env file in the top level folder, or specify the path when calling .config({ path: ... })
chess_legend
chess_legendOP10mo ago
yes that worked thanks also another question for this code i am not getting the slash commands to be registered [nodemon] 3.1.0 [nodemon] to restart at any time, enter rs [nodemon] watching path(s): . [nodemon] watching extensions: js,mjs,cjs,json [nodemon] starting node index.js ✅ kaushi annoyer#4363 is online. [nodemon] restarting due to changes... [nodemon] starting node index.js ✅ kaushi annoyer#4363 is online.
Want results from more Discord servers?
Add your server