fyrebirdd
fyrebirdd
DIAdiscord.js - Imagine an app
Created by fyrebirdd on 3/19/2024 in #djs-questions
401 error on get request
I'm trying to get a list of all of my guild application commands for this bot but I'm getting a 401 error on this rest request and i haven't the slightest idea why. Code:
import { REST, Routes } from 'discord.js';

const rest = new REST().setToken(process.env.TEMPLATE_TOKEN);
var data;

try{
data = await rest.get(
Routes.applicationGuildCommands(
process.env.TEMPLATE_CLIENT_ID,
process.env.TEMPLATE_GUILD_ID
)
);
console.log(data);
}
catch(error){
console.log(error);
}
import { REST, Routes } from 'discord.js';

const rest = new REST().setToken(process.env.TEMPLATE_TOKEN);
var data;

try{
data = await rest.get(
Routes.applicationGuildCommands(
process.env.TEMPLATE_CLIENT_ID,
process.env.TEMPLATE_GUILD_ID
)
);
console.log(data);
}
catch(error){
console.log(error);
}
Error:
DiscordAPIError[0]: 401: Unauthorized
at handleErrors (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:1120:23)
at async SequentialHandler.queueRequest (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:953:14)
at async _REST.request (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:1266:22)
at async file:///C:/code/ts-discord-bot/testing.js:8:12 {
requestBody: { files: undefined, json: undefined },
rawError: { message: '401: Unauthorized', code: 0 },
code: 0,
status: 401,
method: 'GET',
url: 'https://discord.com/api/v10/applications/1128470111607607307/guilds/667849155627974656/commands'
}
DiscordAPIError[0]: 401: Unauthorized
at handleErrors (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:1120:23)
at async SequentialHandler.queueRequest (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:953:14)
at async _REST.request (C:\code\ts-discord-bot\node_modules\@discordjs\rest\dist\index.js:1266:22)
at async file:///C:/code/ts-discord-bot/testing.js:8:12 {
requestBody: { files: undefined, json: undefined },
rawError: { message: '401: Unauthorized', code: 0 },
code: 0,
status: 401,
method: 'GET',
url: 'https://discord.com/api/v10/applications/1128470111607607307/guilds/667849155627974656/commands'
}
I'm loading the environment variables using dotenv (which I've confirmed loads them). I've tried regenerating the token and giving my bot application-commands scope in OAuth but neither worked. I'm using node v21.5.0 and djs v14.14.1. Probably an easy answer, but i appreciate any guidance you can give, I'm quite new to this bot stuff :D
8 replies