Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Passing a discord.js client through workerdata throws an error #249

Open
3 tasks done
seirdotexe opened this issue Jun 1, 2024 · 0 comments
Open
3 tasks done
Labels
bug Something isn't working

Comments

@seirdotexe
Copy link

seirdotexe commented Jun 1, 2024

Describe the bug

Node.js version: 20.14.0

OS version: Windows 11 Pro 23H2

Description: The discord.js client cannot be passed through workerData. I have to do this, because I need it in my jobs.

Actual behavior

It should pass the discord.js client so I can use it in my jobs.

Expected behavior

I receive the following error:

node:internal/per_context/domexception:53
    ErrorCaptureStackTrace(this);
    ^
DOMException [DataCloneError]: (_, shardId) => {
      for (const [guildId, adapter] of this.adapters.entries()) {
        if (client.guilds.c...<omitted>... } could not be cloned.
    at new DOMException (node:internal/per_context/domexception:53:5)
    at new Worker (node:internal/worker:266:17)
    at Bree.createWorker (C:\Users\seir\Documents\GitHub\SMERSH\node_modules\bree\src\index.js:764:12)
    at Bree.run (C:\Users\seir\Documents\GitHub\SMERSH\node_modules\bree\src\index.js:384:35)
    at C:\Users\seir\Documents\GitHub\SMERSH\node_modules\bree\src\index.js:605:18
    at Timeout.fireNow (C:\Users\seir\Documents\GitHub\SMERSH\node_modules\safe-timers\index.js:36:10)
    at Timeout.fired (C:\Users\seir\Documents\GitHub\SMERSH\node_modules\safe-timers\index.js:25:11)
    at listOnTimeout (node:internal/timers:575:11)
    at process.processTimers (node:internal/timers:514:7)

Code to reproduce

// index.js
import Bree from 'bree';
import { Client, GatewayIntentBits } from 'discord.js';

const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const bree = new Bree({
  jobs: [
    {
      name: 'test',
      worker: { workerData: { client } }
    }
  ]
});

await bree.start();

// jobs/test.js
console.log('Test');

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@seirdotexe seirdotexe added the bug Something isn't working label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant