oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.2k stars 2.58k forks source link

Discord.js - 'The operation was aborted' after client.destroy #5185

Open robobun opened 10 months ago

robobun commented 10 months ago
[dp] Logging in...
[dp] My name is GLOS 95 Plus!#4298
[dp] Sent text: test
[dp] Logged off
167 |   }
168 | }
169 | 
170 | class AbortError extends Error {
171 | 
172 |   constructor() {
                             ^
error: The operation was aborted
 code: "ABORT_ERR"

      at new AbortError (node:timers/promises:172:26)
      at node:timers/promises:46:34
      at /home/zulc22/tubearchive-next/node_modules/@discordjs/ws/dist/index.js:710:6
      at destroy (/home/zulc22/tubearchive-next/node_modules/@discordjs/ws/dist/index.js:691:16)
      at /home/zulc22/tubearchive-next/node_modules/@discordjs/ws/dist/index.js:1194:20
      at destroy (/home/zulc22/tubearchive-next/node_modules/@discordjs/ws/dist/index.js:1191:16)
      at /home/zulc22/tubearchive-next/node_modules/discord.js/src/client/websocket/WebSocketManager.js:329:10
      at destroy (/home/zulc22/tubearchive-next/node_modules/discord.js/src/client/websocket/WebSocketManager.js:324:18)
      at /home/zulc22/tubearchive-next/node_modules/discord.js/src/client/Client.js:251:10
import { Client, GatewayIntentBits, TextChannel, Events } from 'discord.js';

export class Dispost {
    client: Client = new Client({ intents: [GatewayIntentBits.Guilds] });
    channel: TextChannel | null = null;
    constructor() {
        if (Bun.env.TOKEN === null) throw new Error("TOKEN has not been specified in environment (for module_discord)");
        this.client.once(Events.ClientReady, async(c: Client) => {
            console.log(`[dp] My name is ${c.user.tag}`);
            if (Bun.env.CHANNEL === null) throw new Error("CHANNEL has not been specified in environment (for module_discord)");
            this.channel = await this.client.channels.fetch(Bun.env.CHANNEL as string) as TextChannel;
            if (this.channel === null) throw new Error(`Couldn't find channel ${Bun.env.CHANNEL}.`);
        });
        console.log("[dp] Logging in...");
        this.client.login(Bun.env.TOKEN);
    }
    async waitForReady() {
        if (this.client.isReady()) return;
        else await new Promise<void>((p,r)=>{this._waitForReady(p,r)});
    }
    _waitForReady(resolve:Function, reject:Function): void {
        if (this.client.isReady()) resolve();
        else setTimeout(()=>{
            this._waitForReady(resolve, reject);
        }, 50);
    }
    async postMessage(message: string) {
        await this.waitForReady();
        console.log("[dp] Sent text:",message);
        await this.channel?.send(message);
    }
    async destroy() {
        await this.client.destroy();
        console.log("[dp] Logged off");
    }
}

Originally reported on Discord: Discord.js - 'The operation was aborted' after client.destroy

sirenkovladd commented 10 months ago

Looks very similar to https://github.com/oven-sh/bun/issues/5021

danny-avila commented 6 months ago

Have this issue as well when abortController is aborted.

FireStreaker2 commented 5 months ago

had this issue too with bun and discord.js, turns out i didn't enable the intents i used in my code in my discord developer panel. after switching them on, it started to work