Expected token to be set for this request, but none was present

I started to use discordjs/rest for some of my stuff to have less api calls in my overall code. One of those being the following
await this.client.rest.post(
`/channels/${message?.channelId}/messages/${apiReturnValue.id}/threads`,
{
body: {
name: `${[
date.getFullYear(),
date.getMonth() + 1,
date.getDate(),
].join("/")} - Daily Message`,
auto_archive_duration: "1440",
},
},
);
await this.client.rest.post(
`/channels/${message?.channelId}/messages/${apiReturnValue.id}/threads`,
{
body: {
name: `${[
date.getFullYear(),
date.getMonth() + 1,
date.getDate(),
].join("/")} - Daily Message`,
auto_archive_duration: "1440",
},
},
);
It should in theory work just fine but for some reason its complaining about a token not being set. I tried to use client.rest.setToken but that doesnt seem to work either. Is there something im missing?
12 Replies
d.js toolkit
d.js toolkit8mo 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!
536b656c6c79
536b656c6c798mo ago
Joining in.
Dominik on vacation
We are using discordjs/rest v2.2.0 and discord.js v14.14.1 Well it add a thread to a message I would need to get the channel -> the message -> then add a thread I havent found a function yet where it just takes in a message id and then adds a thread I dont think that is the case for us as there is nothign else logged besides that token thing that could error Oh thanks I will look into that. Still weird it doesnt work with the rest way tho
Dominik on vacation
Like this where WouldYou is the class We extend the client from and call using this import WouldYou from "./wouldYou";
No description
Dominik on vacation
Oh no wait its being passed in the constructor We pass in the this keyword which should be the client we extend
Dominik on vacation
the same one we use to login
No description
Dominik on vacation
Yea sure one second
Dominik on vacation
GitHub
client/src/util/wouldYou.ts at main · Would-You-Bot/client
Elevate your server's engagement with Would You, featuring user voting, daily messages, and customizability. Would You Rather - Would-You-Bot/client
536b656c6c79
536b656c6c798mo ago
dogeHaHa
Dominik on vacation
I think the sharder we use sets the DISCORD_TOKEN env variable hence why login works. The one we pass into the env is TOKEN so that cant be it yes We had that removed before but then that token issue came up so we added it above the thread line This is so confusing tbh doesnt make any sense to why it would complain about the token
Dominik on vacation
This is the one I have from sentry which is a bit outdated cause it shows the old code there
No description
Dominik on vacation
Ill get that done tomorrow dont got much time today thanks for the help! I found the issue
Want results from more Discord servers?
Add your server