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

As of today, multiple devs have been reporting the error mentioned in the title. In my case, the bot's code has not been changed for months and the error started occurring randomly earlier today. The token in use is valid. The error seems to occur when the bot starts interacting with the discord API (e.g.: when calling channel.setParent).
No description
21 Replies
d.js toolkit
d.js toolkit6mo 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! - Marked as resolved by OP
Portalz
Portalz6mo ago
Error: Expected token to be set for this request, but none was present
at _REST.resolveRequest (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:313:11)
at _REST.queueRequest (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:255:44)
at _REST.request (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:210:31)
at _REST.post (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:181:15)
at GuildChannelManager.create (D:dir\node_modules\discord.js\src\managers\GuildChannelManager.js:183:41)
at Object.addCategory (D:dir\src\discordTools\discordTools.js:189:45)
at module.exports (D:dir\src\discordTools\SetupGuildCategory.js:32:39)
at DiscordBot.setupGuild (D:dir\src\structures\DiscordBot.js:214:75)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.execute (D:dir\src\discordEvents\ready.js:73:13)
Error: Expected token to be set for this request, but none was present
at _REST.resolveRequest (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:313:11)
at _REST.queueRequest (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:255:44)
at _REST.request (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:210:31)
at _REST.post (D:dir\node_modules\discord.js\node_modules\@discordjs\rest\src\lib\REST.ts:181:15)
at GuildChannelManager.create (D:dir\node_modules\discord.js\src\managers\GuildChannelManager.js:183:41)
at Object.addCategory (D:dir\src\discordTools\discordTools.js:189:45)
at module.exports (D:dir\src\discordTools\SetupGuildCategory.js:32:39)
at DiscordBot.setupGuild (D:dir\src\structures\DiscordBot.js:214:75)
at processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.execute (D:dir\src\discordEvents\ready.js:73:13)
same issue - Removed bot from the target Guild - Re-invited bot with admin perms onto same guild - Bot fails to create a category on said guild at GuildChannelManager.create
const data = await this.client.rest.post(Routes.guildChannels(this.guild.id), {
body: {
name,
topic,
type,
nsfw,
bitrate,
user_limit: userLimit,
parent_id: parent,
position,
permission_overwrites: permissionOverwrites,
rate_limit_per_user: rateLimitPerUser,
rtc_region: rtcRegion,
video_quality_mode: videoQualityMode,
default_thread_rate_limit_per_user: defaultThreadRateLimitPerUser,
available_tags: availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
default_reaction_emoji: defaultReactionEmoji && transformGuildDefaultReaction(defaultReactionEmoji),
default_auto_archive_duration: defaultAutoArchiveDuration,
default_sort_order: defaultSortOrder,
default_forum_layout: defaultForumLayout,
},
reason,
});
return this.client.actions.ChannelCreate.handle(data).channel;
}
const data = await this.client.rest.post(Routes.guildChannels(this.guild.id), {
body: {
name,
topic,
type,
nsfw,
bitrate,
user_limit: userLimit,
parent_id: parent,
position,
permission_overwrites: permissionOverwrites,
rate_limit_per_user: rateLimitPerUser,
rtc_region: rtcRegion,
video_quality_mode: videoQualityMode,
default_thread_rate_limit_per_user: defaultThreadRateLimitPerUser,
available_tags: availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
default_reaction_emoji: defaultReactionEmoji && transformGuildDefaultReaction(defaultReactionEmoji),
default_auto_archive_duration: defaultAutoArchiveDuration,
default_sort_order: defaultSortOrder,
default_forum_layout: defaultForumLayout,
},
reason,
});
return this.client.actions.ChannelCreate.handle(data).channel;
}
June
June6mo ago
same issue, message sent in the first second work and nothing work after that
Portalz
Portalz5mo ago
manually checked token prior to it being set, its correct
No description
June
June5mo ago
It's seem that the token is unset like 1-2secs after login So, we're stuck ?
Portalz
Portalz5mo ago
where can u check this
June
June5mo ago
just did targetChannel.send(message) right after login and 5s after in a setInterval
Portalz
Portalz5mo ago
ohh i see
pocin
pocin5mo ago
got the same issue, out of the blue, no code changes. Can confirm that token is unset after first call
const bot = new Client({intents: []});
await bot.login(botToken);

console.log(bot.token) // shows token
await bot.user.setUsername('foo'); // works
console.log(bot.token) // undefined
const bot = new Client({intents: []});
await bot.login(botToken);

console.log(bot.token) // shows token
await bot.user.setUsername('foo'); // works
console.log(bot.token) // undefined
https://github.com/discordjs/discord.js/blob/43160a6ad75e233fff2be1277e6f2360f918c78d/packages/discord.js/src/structures/ClientUser.js#L64-L77 my hunch is that the api call is not giving back a valid token no indication that the API response should include the token in the first place https://discord.com/developers/docs/resources/user#user-object so i must be missing something obvious
harnes.xyz
harnes.xyz5mo ago
Seems like you all are right
No description
No description
June
June5mo ago
but everything worked fine hours ago :blobreachReverse:
pocin
pocin5mo ago
git blame shows no recent changes to the relevant code
No description
June
June5mo ago
you guys use settimeout or something like that ? my embed message won't send even after first login in minimal code, i do not have
Error: Expected token to be set for this request, but none was present
Error: Expected token to be set for this request, but none was present
i'm wonder if it's setTimeout or something like that yes ho, it's working now :d thanks
GitHub
GitHub5mo ago
:pr_open: #10953 in discordjs/discord.js by Jiralite opened <t:1750849756:R> (review required) fix(ClientUser): Remove token assignment
aris
aris5mo ago
@Jiralite can we get this for dev too? we currently utilize the dev version in prod and i have noticed it thank you :rolypoly:
Hexagon
HexagonOP5mo ago
Thanks @Jiralite ! Appreciate the fast follow up
aris
aris5mo ago
i am grateful for your prompt attention and resolution :rolypoly:
Portalz
Portalz5mo ago
thanks! Have a fantastic day 🙂 commented out those 2 lines earlier today, srry forgot to update regarding it, but it did fix the issue for me
Hexagon
HexagonOP5mo ago
🙇‍♂️ Awesome! And thanks everyone else for your input and additional info posted on this issue.
Ed123
Ed1235mo ago
@here I have same issue on it
souji
souji5mo ago
unsurprisingly the solution is also the same - update to 14.21.0

Did you find this page helpful?