Repository navigation
Expand file tree
/
Copy pathinstall_links.py
More file actions
60 lines (49 loc) · 1.58 KB
/
Copy pathinstall_links.py
File metadata and controls
60 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Canonical Discord install links and reusable install controls."""
from __future__ import annotations
from urllib.parse import urlencode
import discord
DISCORD_CLIENT_ID = "1173820242305224764"
SERVER_INSTALL_PERMISSIONS = 274878295040
_DISCORD_AUTHORIZE_URL = "https://discord.com/oauth2/authorize"
def _discord_install_url(
*,
integration_type: int,
scope: str | None = None,
permissions: int | None = None,
) -> str:
query = {
"client_id": DISCORD_CLIENT_ID,
"integration_type": str(integration_type),
}
if scope:
query["scope"] = scope
if permissions is not None:
query["permissions"] = str(permissions)
return f"{_DISCORD_AUTHORIZE_URL}?{urlencode(query)}"
USER_INSTALL_URL = _discord_install_url(
integration_type=1,
scope="applications.commands",
)
SERVER_INSTALL_URL = _discord_install_url(
integration_type=0,
scope="bot applications.commands",
permissions=SERVER_INSTALL_PERMISSIONS,
)
def build_install_controls() -> tuple[tuple[discord.ui.Button, discord.ui.Button], ...]:
"""Return the two explicit Discord install choices used by public commands."""
return (
(
discord.ui.Button(
label="Install to My Account",
style=discord.ButtonStyle.link,
url=USER_INSTALL_URL,
emoji="👤",
),
discord.ui.Button(
label="Add to Server",
style=discord.ButtonStyle.link,
url=SERVER_INSTALL_URL,
emoji="🏠",
),
),
)