Skip to content

Commit 3fe79b2

Browse files
authored
Merge pull request #13 from Furnyr/feat/external-instance
Accept an external instance (v1.3.0)
2 parents c256e0c + 1487190 commit 3fe79b2

11 files changed

Lines changed: 410 additions & 693 deletions

File tree

examples/externalInstance.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
# Using an external SDK instance
3+
4+
If you need access to the SDK instance, using the npm package v1.3.0+ you can pass a promise to the `useSdk` function, but you will need to handle authorization and authentication as documented here:
5+
6+
https://discord.com/developers/docs/activities/how-activities-work#sample-code-and-activity-lifecycle-diagram
7+
8+
---
9+
10+
`index.ts`
11+
12+
```ts
13+
import { useSdk, DiscordSDK, DataPromise } from "dissonity";
14+
15+
window.addEventListener("DOMContentLoaded", async () => {
16+
17+
const discordSdk = new DiscordSDK(/* Client id */);
18+
19+
const promise: DataPromise = new Promise(async resolve => {
20+
21+
await discordSdk.ready();
22+
23+
// (Authorization process...)
24+
25+
const { user } = await discordSdk.commands.authenticate({
26+
access_token: /* Retrieved access token */,
27+
});
28+
29+
resolve({ discordSdk, user });
30+
});
31+
32+
useSdk(promise);
33+
});
34+
```

0 commit comments

Comments
 (0)