#Closed

102 messages · Page 1 of 1 (latest)

loud muralBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

last moss
#

RPC - IPC connection directly closed

south pulsar
#

because the client closes?

#

iirc rpc is abandoned and it doesnt reconnect upon disconnects

#
try {
  await ...;
  // ...
} catch (error) {
  if (error.message != "connection closed") return;
  client.login({ clientId, scopes });
}```
#

no idea if that works though

south pulsar
#

nah

#

you need to wrap all the code in that, await app the promises and make it a function and call it in the catch

#
// ...
async function main() {
  try {
    await client.login({ clientId, scopes });
    await client.selectTextChannel("123456789012345678");
  } catch (error) {
    if (error.message != "connection closed") return;
    main();
  }
}
main();
#

yes

#

which error

#

maybe just add await new Promise(resolve => setTimeout(resolve, 10000));before main in the catch

wild socket
#

did it work at any point?

winter ore
#

You can't use scopes without clientSecret as I understand

Maybe this can help you: #archive-rpc-help message

Welcome to RPC XD

PD: If your app is in a team, remember to add/invite yourself as an app tester

winter ore
#

Yes, I tried just right now. Also, rpc.api is not valid.

These are the valid scopes

#

This is my code (I'm using TypeScript-ES6)

import RPC from 'discord-rpc';
import applicationCredentials from './applicationCredentials.json';

const clientId = applicationCredentials.applicaitonId;
const clientSecret = applicationCredentials.clientSecret;
const scopes = ['rpc', /*'rpc.api',*/ 'messages.read'];

const client = new RPC.Client({ transport: 'ipc' });

(async () => {
    client.login({ clientId, scopes, clientSecret, redirectUri: 'http://localhost:53134' });

    client.on('ready', () => {
        console.log('Logged in as', client?.application?.name);
        console.log('Authed for user', client?.user?.username);
    });
})();
#
Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

#

Remember that you need to invite yourself as an app tester in the app testers tab if your app is in a team and add the redirect in OAuth2 > General

#

I hope that this help you @last moss, GL

winter ore
#

Yes, because client.login return a Promise<RPCClient>, so you need to use the async function/method

You can name a method like this if you don't want to use the anonymous function/method

async function main() {
  client.login({ clientId, scopes, clientSecret, redirectUri: 'http://localhost:53134' });
  client.on('ready', () => {
    console.log('Logged in as', client?.application?.name);
    console.log('Authed for user', client?.user?.username);
  });
}

main();
#

You must pass an Presence like object

let presence = {details: 'hi');
await client.setActivity(presence);

You can use this as reference:

export interface Presence {
    state?: string | undefined;
    details?: string | undefined;
    startTimestamp?: number | Date | undefined;
    endTimestamp?: number | Date | undefined;
    largeImageKey?: string | undefined;
    largeImageText?: string | undefined;
    smallImageKey?: string | undefined;
    smallImageText?: string | undefined;
    instance?: boolean | undefined;
    partyId?: string | undefined;
    partySize?: number | undefined;
    partyMax?: number | undefined;
    matchSecret?: string | undefined;
    spectateSecret?: string | undefined;
    joinSecret?: string | undefined;
    buttons?: Array<{ label: string; url: string }> | undefined;
}
#

Yeah... you can't set the name and type for some reason, I guess Discord doesn't allow that or the discord-rpc module doesn't support that, so you might only use the interface as example

#

Do you mean just add a status like this?

#

Mmm I don't understand... you want to change the name and activity type of the application (like listening, watching)?

Because that's not possible

#

Be care, self-bots goes against ToS

Activity can be updated every time you use the client.setActivity() function, but it only edits thigs like description an images, just create some templates, let me find some examples

#

For example, every time open my electron app it will load a client, and then an activity will start with the args of the second image. Then If I want to set an activity I just run again the .setActivity() and pass a new object

wild socket
#

name of the activity is the name of the RPC app

#

bots set a text, while rpc uses app name

vapid birch
#

@last moss I'm having the same issue, how did you resolve it?

wild socket
#

you dont

vapid birch
#

for the original connection closed issue

#

i didn't understand it

#

even with the exact code he sent

#

this is so annoying

wild socket
#

time to dig up the old list

#

djs Things to consider when getting a connection closed/could not connect error:
• What transport are you using? If it's 'websocket', change that to 'ipc'.
• Is the ID you are trying to login with your user ID? If so, you should be using a Client ID from the Developer Portal (https://discord.com/developers/applications) instead.
• Is the ID a string? If not, JavaScript will truncate it's value causing the connection to fail.
• Are you using the Discord app? It won't be able to connect to the web version. Similarly, bots cannot use RPC.
• Is your code running on the same machine as the Discord app?
• Are you trying to run it from WSL? If so, it won't be able to connect either.
• Have you installed Discord from the snap store? If so, install it from your distro's package repository or directly from the Discord website.

vapid birch
#

AH MY ID WAS AN INT

#

YOO IT WORKED

#

yoo thanks so mcuh

#

is there a better way to toggle mute instead of getting the mute value and applying ! to it?

wild socket
#

no

vapid birch
#

oh ok

wild socket
#

does "you don't" mean anything else?

#

how what plugins

#

and do what

#

and what does it do

#

...ok?

#

how does that relate to me saying that you can't change the name

#

not the description, status, timestamp, images or image texts

#

the one you sent sets the details field

#

he doesnt

#

he does not touch the app name

#

he sets the details

#

that is this

#

while this is app name and you can't really change that from code

#

no

#

the discord app he is using has "Aquie RPC" here

#

it does not matter what app you run in the background or how it's called

#

it connects to the discord client with an app id

vapid birch
#

one last question

#

every time I relaunch my application, it needs to reauth

#

how do I go about caching the token?

#

nvm got it

wild socket
#

what status

vapid birch
#

well it doesn't work yet, but I'm saving the token in the ready event (client.accessToken) then try catch with login as the token

wild socket
#

you don't have to mention me in every message

#

what is personal status

#

no, not possible

vapid birch
#
let token = localStorage.getItem("discordToken");
if (token) {
    client.login({ clientId, clientSecret, accessToken: localStorage.getItem("discordToken"), scopes, redirectUri: 'http://localhost:53134' });
} else {
    client.login({ clientId, clientSecret, scopes, redirectUri: 'http://localhost:53134' });
}

client.on('ready', () => {
    console.log('Authed for Discord user', client?.user?.username);
    localStorage.setItem("discordToken", client?.accessToken);
});

works

#

also why is #archive-rpc-help archived? is rpc discontinued or is it just replaced with this forum?

wild socket
#

dude

#

i already told you that

#

also, can you stop mentioning me in every message

#
  1. it's a betterdiscord plugin
  2. it's not rpc but custom status
  3. it's extremely API spammy
  4. it's against discord tos
  5. can get your account banned
south pulsar
wild socket
#

vast majority of channels that are in #926900136288878592 are archived due to moving to forums

high bluff
#

Whenever I use both the RPC client and the regular client in the same process, I get a RPC_CONNECTION_TIMEOUT. If I take out the regular client.login or the rpc.login it works just fine, but having them both busts stuff down

For reference, I want to be able to let my program update my (the active user's Rich Presence) and also host the bot instance. It doesn't seem to make a difference if I use my bot's clientId or a different non-bot app for the RPC clientId

high bluff
cunning gorge
#

fyi siris is working on a full refactor of rpc in typescript

#

maybe try using his branch since the abandoned project you’re using now is gonna get replaced :soontm:

void oxide
molten blade
#

@meager oracle

winter ore
#

It looks like your app is not in a team, so it's not necessary to invite yourself

#

It depends, in my case I develop the app with some friends so, I need the app to be in a team

#

Can you show me the code?

#

Mmm

#

Did you add the OAuth2 redirect?

#

Let me try it, wait a moment

#

It worked for me XD

#

Let me share you a zip with my files, please wait

#

Wait I got the same error... but idk from where it comes

winter ore
# winter ore

Yes, in the app you will see a modal like this one

PD: This works again, it's because I deleted the secret and id to share the zip

#

Here is a example in TypeScript for @everyone

Steps:

  • Replace the data inside ./src/applicationCredentials.json
  • Add the redirect in your app (here is the link: https://discord.com/developers/applications/YOURAPPID/oauth2/general), it must be http://localhost:53134 or the same used in Ln 11, Col 66 of the file ./src/main.ts
  • Invite yourself as an app tester if your app is in a team (here is the link https://discord.com/developers/applications/YOURAPPID/testers, then check your email
  • Run the next commands
    -> npm install
    -> npm run build
    -> npm run start
wild socket
#

what link

#

there's this

#

why would i know that

winter ore
#

Check that you are using same configs in your tsconfig.json

#

I only get that error when credentials are missing, try to regenerate your secret

#

Oh, I see... Lol

#

Ntp