#Closed
102 messages · Page 1 of 1 (latest)
RPC - IPC connection directly closed
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
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
did it work at any point?
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
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);
});
})();
Yes I know that, just don't use the other scopes, some scopes are for bot only
https://discord.com/developers/docs/topics/rpc#authorize-authorize-argument-structure
https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
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
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
name of the activity is the name of the RPC app
bots set a text, while rpc uses app name
@last moss I'm having the same issue, how did you resolve it?
you dont
for the original connection closed issue
i didn't understand it
even with the exact code he sent
this is so annoying
time to dig up the old list
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.
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?
no
oh ok
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
one last question
every time I relaunch my application, it needs to reauth
how do I go about caching the token?
nvm got it
what status
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
you don't have to mention me in every message
what is personal status
no, not possible
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?
dude
i already told you that
also, can you stop mentioning me in every message
- it's a betterdiscord plugin
- it's not rpc but custom status
- it's extremely API spammy
- it's against discord tos
- can get your account banned
there is a rpc tag in the forum
vast majority of channels that are in #926900136288878592 are archived due to moving to forums
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
i solved my own problem here, it was some combination of not running the RPC and initiating the bot from the correct electron context. it was probably also compounded by slow network reads of the actual JS itself making the launch time extremely slow so it may have legitimately timed itself out in a way that only ever manifests by doing both of them at once.
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:
the refactor that tristan is talking about
https://github.com/suneettipirneni/discord.js/tree/feat/rpc
@meager oracle
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
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 behttp://localhost:53134or 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