discord RPC error when i try to run the code

1.5k Views Asked by At

when i try to run the code i get this error. i wrote this code with the help of a tutorial in youtube but i don't know what is the mistake i made in this.

Error: Could not connect at Socket.onerror (/home/runner/Toshiro/node_modules/discord-rpc/src/transports/ipc.js:32:16) at Object.onceWrapper (node:events:510:26) at Socket.emit (node:events:390:28) at Socket.emit (node:domain:475:12) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3)

my code:

const clientId = "960430276532645888"
const DiscordRPC = require("discord-rpc");
const RPC = new DiscordRPC.Client({ transport: "ipc" });

DiscordRPC.register(clientId);

async function setActivity() {
  if (!RPC) return;
  RPC.setActivity({
    details: `Reading`,
    state: `all subjects`,
    startTimestamp: Date.now(),
    largeImageKey: `books`,
    largeImageText: `books`,
    smallImageKey: `verified`,
    smallImageText: `verified`,
    instance: false,
    buttons: [
      {
        label: `Join Me :)`,
        url: `https://www.sanfransentinel.com/combine-study.html`,

      },
    ]
  });
};

RPC.on('ready', async () => {
  setActivity();

  setInterval(() => {
    setActivity();
  }, 15 * 1000);
})

RPC.login({ clientId }).catch(err => console.error(err));

how can i solve this problem

1

There are 1 best solutions below

0
On

Take a read through here: https://github.com/iCrawl/discord-vscode/issues/85.

It looks like it may just be the permissions on your computer.

Try running the code editor as admin and make sure Discord isn't running admin. How to run an application as admin.

If you are not running it locally it wont work, the library connects to your local running discord client. If you host it on a different machine it cannot connect anymore.