Skip to content

Commit afa6173

Browse files
authored
Add rich presence example (#880)
1 parent 1d6e87a commit afa6173

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/rich_presence.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import discord
2+
3+
# Your Developer Portal Application ID (used for proxying external assets)
4+
APPLICATION_ID = 123456789012345678
5+
6+
# Any direct image URLs (png/jpg/gif). Discord will proxy these.
7+
LARGE_IMAGE_URL = 'image url here'
8+
SMALL_IMAGE_URL = 'image url here'
9+
10+
11+
class MyClient(discord.Client):
12+
async def on_ready(self):
13+
# Proxy BOTH urls in one call (Discord supports proxying up to 2 at a time).
14+
proxied_large, proxied_small = await self.proxy_external_application_assets(
15+
APPLICATION_ID,
16+
LARGE_IMAGE_URL,
17+
SMALL_IMAGE_URL,
18+
)
19+
20+
activity = discord.Activity(
21+
type=discord.ActivityType.playing,
22+
application_id=APPLICATION_ID,
23+
name='name',
24+
details='details',
25+
state='state',
26+
assets=discord.ActivityAssets(
27+
large_image=proxied_large,
28+
large_text='large_text',
29+
small_image=proxied_small,
30+
small_text='small_text',
31+
),
32+
buttons=[
33+
discord.ActivityButton('Website', 'https://example.com'),
34+
],
35+
)
36+
37+
await self.change_presence(status=discord.Status.online, activity=activity)
38+
print(f'Rich presence applied as {self.user} ({self.user.id})')
39+
40+
41+
client = MyClient()
42+
client.run('token')

0 commit comments

Comments
 (0)