Discord Service

This page contains the technical documentation for the Discord service.

Location: allianceauth.services.modules.discord


Public interface for community apps who want to interact with the Discord server of the current Alliance Auth instance.


Here is an example for using the api to fetch the current roles from the configured Discord server.

from allianceauth.services.modules.discord.api import create_bot_client, discord_guild_id

client = create_bot_client()  # create a new Discord client
guild_id = discord_guild_id()  # get the ID of the configured Discord server
roles = client.guild_roles(guild_id)  # fetch the roles from our Discord server

See also

The docs for the client class can be found here: DiscordClient

class DiscordUser(*args, **kwargs)[source]

The Discord user account of an Auth user.

  • uid (BigIntegerField) – Uid. user’s ID on Discord

  • username (CharField) – Username. user’s username on Discord

  • discriminator (CharField) – Discriminator. user’s discriminator on Discord

  • activated (DateTimeField) – Activated. Date & time this service account was activated

Relationship fields:


user (OneToOneField to User) – Primary key: User. Auth user owning this Discord account (related name: discord)

class Role(id: int, name: str, managed: bool = False)[source]

A role on Discord.

__init__(id: int, name: str, managed: bool = False) None
asdict() dict[source]

Convert object into a dictionary representation.

classmethod from_dict(data: dict) allianceauth.services.modules.discord.discord_client.models.Role[source]

Create object from dictionary as received from the API.

classmethod sanitize_name(role_name: str) str[source]

Shorten too long names if necessary.

create_bot_client(is_rate_limited: bool = True) allianceauth.services.modules.discord.discord_client.client.DiscordClient[source]

Create new bot client for accessing the configured Discord server.


is_rate_limited – Set to False to turn off rate limiting (use with care).


Discord client instance

group_to_role(group: django.contrib.auth.models.Group) Optional[allianceauth.services.modules.discord.discord_client.models.Role][source]

Fetch the Discord role matching the given Django group by name.


Discord role or None if no matching role exist

server_name(use_cache: bool = True) str[source]

Fetches the name of the current Discord server.


use_cache – When set False will force an API call to get the server name


Server name or an empty string if the name could not be retrieved


DISCORD_APP_ID = 'appid'

App ID for the AA bot on Discord. Needs to be set.


App secret for the AA bot on Discord. Needs to be set.

DISCORD_BOT_TOKEN = 'bottoken'

Token used by the AA bot on Discord. Needs to be set.

DISCORD_CALLBACK_URL = 'http://example.com/discord/callback'

Callback URL for OAuth with Discord. Needs to be set.

DISCORD_GUILD_ID = '0118999'

ID of the Discord Server. Needs to be set.


Automatically sync Discord users names to user’s main character name when created.


Max retries of tasks after an error occurred.


Pause in seconds until next retry for tasks after the API returned an error.