mirror of
https://github.com/discordjs/discord.js.git
synced 2026-09-18 01:07:26 +00:00
* feat: rpc * chore: update CODEOWNERS * fix: linter rules * chore: add rpc to workflows and readme * chore: remove rpc tests folder * chore: add package details from rpc repo * docs: rpc docs readme * chore: fix rpc license * chore: remove vitest * fix: rpc links * build: dependencies * docs: "id" * chore: awkward doc spacing * chore: lockfile * chore: clean stuff * fix: apply suggested changes * chore: suggested changes * chore: suggested changes * chore: suggested changes * fix: silly things * chore: suggested changes * chore: suggested changes * chore: suggested changes * chore: suggested changes * suggested changes * remove examples in favor of later guide additions * add very basic guide for rpc * meta config changes for guide * guide changes * suggested changes * suggested changes * Update packages/rpc/package.json Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> * Update packages/rpc/package.json * fix: revert version bumps, use esm * fix regression from suggested change * suggested changes * forgot to remove extra image --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
59 lines
1.2 KiB
Plaintext
59 lines
1.2 KiB
Plaintext
---
|
|
title: Usage
|
|
---
|
|
|
|
### Legend
|
|
|
|
- `client` is a placeholder for the `RPCClient` object, such as `const client = new RPCClient({ scopes: [Oauth2Scopes.MessagesRead] });`.
|
|
|
|
### Authorization
|
|
|
|
Authorizing your client:
|
|
|
|
```ts
|
|
client.login({ clientId: env.CLIENT_ID, clientSecret: env.CLIENT_SECRET });
|
|
```
|
|
|
|
If the current user has already been authorized recently:
|
|
|
|
```ts
|
|
client.login({ clientId: env.CLIENT_ID, accessToken: env.ACCESS_TOKEN });
|
|
```
|
|
|
|
Optionally, if you aren't requesting for any scopes, you can exclude the client secret:
|
|
|
|
```ts
|
|
client.login({ clientId: env.CLIENT_ID });
|
|
```
|
|
|
|
### RPC Commands
|
|
|
|
Update a user's activity:
|
|
|
|
```ts
|
|
let updatesDoneSinceStart = 0;
|
|
|
|
setInterval(async () => {
|
|
await client.setActivity({
|
|
details: 'Doing silly things: ${updatesDoneSinceStart}',
|
|
state: 'Silly stuff :3',
|
|
name: 'Silly',
|
|
type: 1,
|
|
});
|
|
|
|
updatesDoneSinceStart++;
|
|
}, 15_000);
|
|
```
|
|
|
|
### RPC Events
|
|
|
|
Listen for messages on the current user's discord client:
|
|
|
|
<Callout>Listening for messages requires the scope `messages.read`</Callout>
|
|
|
|
```ts
|
|
client.on(RPCEvents.MessageCreate, (data: RPCMessageCreateDispatchData) =>
|
|
console.log(`${data.message.author.username} posted ${data.message.content}`),
|
|
);
|
|
```
|