-
Notifications
You must be signed in to change notification settings - Fork 30
async/await strange undefined behavior #96
Comments
I don't see how this is an issue with the rest module, but it might be with your code. Please make a minimum reproduction sample, and report back if the issue persists! |
Hiya @vladfrangu, I think this may be a minimum reproduction sample: import { setTimeout } from "node:timers/promises";
import { Routes } from "discord-api-types/v9";
import { REST } from "@discordjs/rest";
class test {
REST = new REST().setToken(process.env.DISCORD_TOKEN ?? "");
async deleteMessages(channelId, messageIds) {
for (const messageId of messageIds) {
await this.REST.delete(Routes.channelMessage(channelId, messageId)).catch(() => null); // Ignore errors
// await setTimeout(1000);
}
}
};
const testing = new test();
const messageIds = []; // Put message ids here
const output = await testing.deleteMessages("channel_id", messageIds);
console.log(output); Populate the If the process is kept alive, all message ids will be deleted. Additionally, uncommenting the Also, |
Thanks for that code sample @Jiralite that is basically the behavior I’m seeing as well with command deployment. async/await doesn’t seem to work right with this module. |
This is because timers are unref'd:
Since the sleep is done with |
It's also weird that using .then/.catch would solve the issue because await uses the Promise prototype methods under the hood. |
I did some more testing on this and I don't think I was accurate about that. They had similar issues. |
Issue description
When I deploy the following code using async/await my application exits immediately with no error code intermittently (usually 1 of every 4 or 5 tries).
Code sample
discord.js version
13.13.1
Node.js version
v16.13.0
Operating system
MacOS
Priority this issue should have
Medium (should be fixed soon)
Which partials do you have configured?
No Partials
Which gateway intents are you subscribing to?
GUILDS
The text was updated successfully, but these errors were encountered: