discordjs / RPC

A simple RPC client for Discord
MIT License
459 stars 190 forks source link

Could not connect on Linux #177

Closed rhaym-tech closed 10 months ago

rhaym-tech commented 10 months ago

I wrote a simple code to run a custom rich presence on MacOS and tested it too in Windows, but now when I'm using Debian it gives me this error:

> node .

/home/rhaym/Documents/DJS-RichPresence/node_modules/discord-rpc/src/transports/ipc.js:32
        reject(new Error('Could not connect'));
               ^

Error: Could not connect
    at Socket.onerror (/home/rhaym/Documents/DJS-RichPresence/node_modules/discord-rpc/src/transports/ipc.js:32:16)
    at Object.onceWrapper (node:events:629:26)
    at Socket.emit (node:events:514:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.5.1

Code:

const { Client } = require('discord-rpc');
const { DETAILS, STATE, LARGE_IMAGE, LARGE_TEXT, SMALL_IMAGE, SMALL_TEXT, BUTTONS } = require('./config');
const checkConfig = require('./helpers/checkConfig');
require("dotenv").config();
checkConfig();
const client = new Client({
    transport: 'ipc'
});

client.on('ready', async () => {
    console.log("Loading Rich Presence...");
    try {
        await client.request('SET_ACTIVITY', {
            pid: process.pid,
            activity: {
                details: DETAILS,
                state: STATE,
                timestamps: {
                    start: Date.now()
                },
                assets: { //comment this part if you don't want to add images or comment a specific part
                    large_image: LARGE_IMAGE,
                    large_text: LARGE_TEXT,
                    small_image: SMALL_IMAGE,
                    small_text: SMALL_TEXT
                },
                buttons: BUTTONS
            }
        });
        console.log("Rich Presence loaded successfully");
    } catch (error) {
        console.error("Error loading Rich Presence", error);
    }
});

client.login({
    clientId: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET
});
rhaym-tech commented 10 months ago

I'm sorry but I just realised the problem is from Discord itself, now installed an update and it got fixed