diff options
| author | Rapptz <[email protected]> | 2016-04-08 22:51:57 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-04-08 22:51:57 -0400 |
| commit | eedad13ac1debdcce97e895078912b5729e0a2c7 (patch) | |
| tree | 95ef594f3573afbf26c5a53b671bf71b06a0b7a5 /discord/utils.py | |
| parent | Change all email/password pair examples to use token. (diff) | |
| download | discord.py-eedad13ac1debdcce97e895078912b5729e0a2c7.tar.xz discord.py-eedad13ac1debdcce97e895078912b5729e0a2c7.zip | |
Add utility function for generating OAuth2 urls.
Diffstat (limited to 'discord/utils.py')
| -rw-r--r-- | discord/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/discord/utils.py b/discord/utils.py index 20a91b6f..11dcb3f0 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -74,6 +74,25 @@ def parse_time(timestamp): return datetime.datetime(*map(int, re_split(r'[^\d]', timestamp.replace('+00:00', '')))) return None + +def oauth_url(client_id, permissions=None): + """A helper function that returns the OAuth2 URL for inviting the bot + into servers. + + Parameters + ----------- + client_id : str + The client ID for your bot. + permissions : :class:`Permissions` + The permissions you're requesting. If not given then you won't be requesting any + permissions. + """ + url = 'https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot'.format(client_id) + if permissions is not None: + url = url + '&permissions=' + str(permissions.value) + return url + + def snowflake_time(id): """Returns the creation date in UTC of a discord id.""" return datetime.datetime.utcfromtimestamp(((int(id) >> 22) + DISCORD_EPOCH) / 1000) |