Skip to content

Commit f25c41d

Browse files
committed
feat(content): add monetization/premium apps page
1 parent e3b801b commit f25c41d

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed
76 KB
Loading
21.4 KB
Loading

guide/docs/popular-topics/intro.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ use-cases.
110110
</div>
111111
</div>
112112
</div>
113+
<div class="row">
114+
<div class="col padding-vert--md">
115+
<div class="card">
116+
<div class="card__image">
117+
<a href="/popular-topics/monetization">
118+
<img src={require('./images/monetization-intro.png').default} alt="Monetization Intro Image" />
119+
</a>
120+
</div>
121+
<div class="card__body">
122+
<a href="/popular-topics/monetization">
123+
<h3>Monetization</h3>
124+
</a>
125+
<div>Add premium features to your bot.</div>
126+
</div>
127+
</div>
128+
</div>
129+
<br />
130+
<div class="col padding-vert--md"></div>
131+
<br />
132+
<div class="col padding-vert--md"></div>
133+
</div>
113134
</div>
114135

115136
## Resulting Code
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
description: Add premium features to your bot.
3+
---
4+
5+
# Monetization
6+
7+
:::note
8+
9+
Monetization is limited to **verified** apps/bots.
10+
11+
:::
12+
13+
Premium Apps offer developers the ability to monetize their application through monthly recurring subscriptions, natively on Discord.
14+
This allows you to e.g. restrict specific commands or other functionality to premium users/guilds.
15+
16+
Not all applications are eligible - your app must be verified, part of a developer team, and use [slash commands](/interactions/slash-commands) or the privileged `Message Content` intent, among other things.
17+
18+
## Initial setup
19+
20+
To get started, visit the [official documentation](https://discord.com/developers/docs/monetization/overview) to see the full list of requirements, and configure your app for monetization by following the steps outlined there.
21+
22+
## Retrieving entitlements
23+
24+
Entitlements represent access to the premium functionality of your application. These can be granted to users or guilds, depending on how you set up monetization in the previous step, and contain a start/end date.
25+
26+
In [interactions](/interactions) (e.g. slash commands), the entitlements for the invoking user/guild are easily accessible using <DocsLink reference="disnake.Interaction.entitlements" />.
27+
28+
Outside of interactions, you can fetch entitlements using <DocsLink reference="disnake.Client.entitlements">Client.entitlements()</DocsLink>, optionally only fetching entitlements of a specific user or guild. Note that this may include expired entitlements, unless you pass the `exclude_ended` parameter.
29+
30+
To check whether an entitlement is still active, you can use <DocsLink reference="disnake.Entitlement.is_active">Entitlement.is_active()</DocsLink>.
31+
32+
## Premium interactions
33+
34+
This is usually the main way to provide premium functionality.
35+
Application commands are not preemptively marked as "premium-only" - instead, you may respond to interactions with a new response type: <DocsLink reference="disnake.InteractionResponse.require_premium" />.
36+
37+
This will display an ephemeral message to the invoking user, prompting them to upgrade:
38+
39+
```python
40+
@bot.slash_command()
41+
async def command(inter: disnake.ApplicationCommandInteraction):
42+
if not inter.entitlements:
43+
await inter.response.require_premium()
44+
return # skip remaining code
45+
...
46+
```
47+
48+
<p align="center">
49+
<img
50+
src={require('./images/monetization-response.png').default}
51+
alt="Premium Interaction Response Type"
52+
width="75%"
53+
/>
54+
</p>
55+
56+
## Events
57+
58+
Whenever users subscribe or renew a subscription with your app, you will receive an <DocsLink reference="disnake.on_entitlement_create" /> or <DocsLink reference="disnake.on_entitlement_update" /> event respectively.
59+
In the case of renewals, the <DocsLink reference="disnake.Entitlement.ends_at">ends_at</DocsLink> attribute of the entitlement you receive from the event will reflect the new expiry date.
60+
61+
:::note
62+
While an <DocsLink reference="disnake.on_entitlement_delete" /> event also exists, it will not fire when a subscription expires; it only occurs e.g. in case of refunds or due to manual removal by Discord.
63+
:::
64+
65+
## Testing entitlements
66+
67+
You can create test entitlements using <DocsLink reference="disnake.Client.create_entitlement" /> and delete them using <DocsLink reference="disnake.Entitlement.delete" />, which allows you to test your implementation in various subscription states. These entitlements do not expire and therefore have no start/end date.
68+
69+
If you want to test the full payment flow, you can go through the same upgrade steps as any other user of your application would - all members of the app's associated team automatically receive a 100% discount on the subscription. Note that you cannot delete these entitlements, unlike the test entitlements mentioned before.

guide/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const sidebars = {
4646
'popular-topics/permissions',
4747
'popular-topics/errors',
4848
'popular-topics/intents',
49+
'popular-topics/monetization',
4950
],
5051
},
5152
{

0 commit comments

Comments
 (0)