Discord Service

This page contains the technical documentation for the Discord service.

Location: allianceauth.services.modules.discord

api

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

Example

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.

Parameters:
  • 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:

Parameters:

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) 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) DiscordClient[source]

Create new bot client for accessing the configured Discord server.

Parameters:

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

Returns:

Discord client instance

group_to_role(group: Group) Role | None[source]

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

Returns:

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.

Parameters:

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

Returns:

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

settings

DISCORD_APP_ID = 'appid'

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

DISCORD_APP_SECRET = 'secret'

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.

DISCORD_SYNC_NAMES = False

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

DISCORD_TASKS_MAX_RETRIES = 3

Max retries of tasks after an error occurred.

DISCORD_TASKS_RETRY_PAUSE = 60

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