ABDHP
ABDHP
DIdiscord.js - Imagine ❄
Created by ABDHP on 1/19/2025 in #djs-questions
Working with Rest API
I'm trying to use REST for the first time, but I can't get it to work. I can't find any docs/references on how to perform actions with it. Right now I'm trying to move myself to a different voice channel, here's my code:
import { REST, RESTOptions, Routes } from "discord.js";
import { config } from "./config.js";

const restOptions: Partial<RESTOptions> = {
version: "10",
}
const rest: REST = new REST(restOptions).setToken(config.getToken());

await rest.patch(Routes.guildVoiceState("968047032294072360", "557929338205634561"), {
body: {
channel_id: "968047032294072365",
},
});
import { REST, RESTOptions, Routes } from "discord.js";
import { config } from "./config.js";

const restOptions: Partial<RESTOptions> = {
version: "10",
}
const rest: REST = new REST(restOptions).setToken(config.getToken());

await rest.patch(Routes.guildVoiceState("968047032294072360", "557929338205634561"), {
body: {
channel_id: "968047032294072365",
},
});
gives the following error:
C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:727
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[10065]: Unknown Voice State
at handleErrors (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:1128:23)
at async SequentialHandler.queueRequest (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:959:14)
at async _REST.request (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async file:///C:/Users/ABDHP/Code/dsbot/mafia3/bin/test.js:7:1 {
requestBody: { files: undefined, json: { channel_id: '968047032294072365' } },
rawError: { message: 'Unknown Voice State', code: 10065 },
code: 10065,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/guilds/968047032294072360/voice-states/557929338205634561'
}
C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:727
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[10065]: Unknown Voice State
at handleErrors (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:1128:23)
at async SequentialHandler.queueRequest (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:959:14)
at async _REST.request (C:\Users\ABDHP\Code\dsbot\mafia3\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async file:///C:/Users/ABDHP/Code/dsbot/mafia3/bin/test.js:7:1 {
requestBody: { files: undefined, json: { channel_id: '968047032294072365' } },
rawError: { message: 'Unknown Voice State', code: 10065 },
code: 10065,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/guilds/968047032294072360/voice-states/557929338205634561'
}
How do i get my application to do this specific task, and, if not through support channels like this, how would i figure it out? Using Node.js v20.11.1 & discord.js v14.17.3
5 replies