Invalid Bot Token

Heres my register commands code
...(async () => {
try {
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN1);
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID1, process.env.SERVER_ID1),
{ body: commands }
);
console.log('Successfully registered application commands.');
} catch (e) {
console.error(`There was an error: ${e}`);
}
})();
...(async () => {
try {
const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN1);
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID1, process.env.SERVER_ID1),
{ body: commands }
);
console.log('Successfully registered application commands.');
} catch (e) {
console.error(`There was an error: ${e}`);
}
})();
AND HERES MY CONSOLE There was an error: DiscordAPIError[0]: 401: Unauthorized I understand the simplest answer would be that my token is invalid but i have removed and replaced it like 20 different times to no avail. i have also succesfully run other bots with the same code just fine
7 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!
ChiRhoXP
ChiRhoXPOP10mo ago
{
"dependencies": {
"discord.js": "^14.14.1",
"dotenv": "^16.4.5",
"node-fetch": "^3.3.2",
"winston": "^3.12.0"
},
"name": "invictusbanker",
"version": "1.0.0",
"main": "invictusBanker.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
{
"dependencies": {
"discord.js": "^14.14.1",
"dotenv": "^16.4.5",
"node-fetch": "^3.3.2",
"winston": "^3.12.0"
},
"name": "invictusbanker",
"version": "1.0.0",
"main": "invictusBanker.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
monbrey
monbrey10mo ago
That is the answer, no matter what you claim Must not be being loaded from your environment variables
kin.ts
kin.ts10mo ago
are you sure have env named DISCORD_TOKEN1? and where do you copy the token?
ChiRhoXP
ChiRhoXPOP10mo ago
I copy from 0Auth2 client secret in discord portal and yes
import dotenv from 'dotenv';
dotenv.config();
import dotenv from 'dotenv';
dotenv.config();
kin.ts
kin.ts10mo ago
OAuth2 client secret isn't a token.. you should copy it from the bot section in the dev portal
ChiRhoXP
ChiRhoXPOP10mo ago
ah shit no wonder hold on ugh i feel so dmb thank you it worked found it in bot
Want results from more Discord servers?
Add your server