Module realm_api.discord

Classes

class DiscordClient (user_id, token)
Expand source code
class DiscordClient:
    user_id: str
    token: str

    def __init__(self, user_id, token):
        self.user_id = user_id
        self.token = token

    async def api(self, url):
        async with ClientSession() as http:
            http.headers.add("Authorization", f"Bearer {self.token}")

            async with http.get(
                f"https://discord.com/api/v10{url}"
            ) as response:
                return await response.json()

    async def get_user_info(self):
        return await self.api("/oauth2/@me")

    async def get_guilds(self):
        return await self.api("/users/@me/guilds")

Class variables

var token : str
var user_id : str

Methods

async def api(self, url)
Expand source code
async def api(self, url):
    async with ClientSession() as http:
        http.headers.add("Authorization", f"Bearer {self.token}")

        async with http.get(
            f"https://discord.com/api/v10{url}"
        ) as response:
            return await response.json()
async def get_guilds(self)
Expand source code
async def get_guilds(self):
    return await self.api("/users/@me/guilds")
async def get_user_info(self)
Expand source code
async def get_user_info(self):
    return await self.api("/oauth2/@me")