token error
he umm everything is working fine until all i did was add a comment and then it says token invalid
15 Replies
- 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 OPError [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
Show your code
this is pacage.json
Are you sure .env has the correct token
positive
Try regenerating the token
i did just now
is it not detecting the change
i did control save
You have to put the new token in the .env file
i did
Log process.env and see if it's there
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);Maybe put the.env file in the top level folder, or specify the path when calling
.config({ path: ... })
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.