AA-Discordbot
AA-Discordbot for Alliance Auth.

Features
- Bot Framework, easily extensible with more Cogs
- Integration with Alliance Auth, able to fetch data directly from its django project.
- Channel/Direct messaging feature, with Tasks and a Queue/Consumer
- Current Cogs
- About
- !about - Bot Information and Statistics
- Auth
- !auth or /auth - A direct link to the Auth Install to catch users familiar with other bots.
- Members
- !lookup [search string] - Fetch a users Main, Affiliation, State, Groups and linked characters from any character.
- !altcorp [search string] - search for users with characters in an altcorp
- Remind
- !remindme [5s/m/h/d text] - Sets a simple non-persistent reminder timer when the bot will respond with the text
- Sov
- !vuln [context] - Returns a list of Vulnerable sov structures for a Region/Constellation/Solar_System or alliance
- !sov [context] - Returns a list of all sov structures for a Region/Constellation/Solar_System or alliance
- !lowadm - Lists sov in need of ADM-ing, context provided in settings.
- Time
- !time or /time - Returns the current EVE Time.
- Timers
- !timer - Returns the next Structure timer from allianceauth.timerboard.
- Ticket
- /help and Message context command to create private support threads
- PriceCheck:
- amarr - Check an item price on Amarr market
- jita - Check an item price on Jita market
- price - Check an item price on Jita and Amarr market
- Easter Eggs,
- !happybirthday [text] - Wishes the text a happy birthday, works with user mentions
- WelcomeGoodbye
- Welcome - Responds to user join events with predefined messages.
- Goodbye - Responds to user leave events with predefined messages.
- Admin
- Slash commands to help with setting up a discord server when you are not admin or owner.
- accessed via
/admin [command]
- add_role / add_role_read / rem_role - add/remove a role to a channel
- new_channel - create a new channel and assign it a role for read access
- promote_role_to_god/demote_role_to_god - promote/demote a role to/from full admin so for when you need it
- empty_roles - list all roles on server with no members
- clear_empty_roles - remove all empty roles from the server
- orphans - find any user in discord with no auth user attached
- get_webhooks - returns any webhooks setup in this current channel, or creates one for you and returns that
- uptime - how long the bot has been up for
Installation

- [BARE METAL ONLY] Install the app with your venv active
pip install allianceauth-discordbot
-
Add 'aadiscordbot',
to your INSTALLED_APPS list in local.py.
-
Add the below lines to your local.py
settings file, Changing the contexts to yours.
ADMIN_DISCORD_BOT_CHANNELS = [111, 222, 333]
SOV_DISCORD_BOT_CHANNELS = [111, 222, 333]
ADM_DISCORD_BOT_CHANNELS = [111, 222, 333]
DISCORD_BOT_SOV_STRUCTURE_OWNER_IDS = [1000169]
DISCORD_BOT_MEMBER_ALLIANCES = [111, 222, 333]
DISCORD_BOT_ADM_REGIONS = [10000002]
DISCORD_BOT_ADM_SYSTEMS = [30000142]
DISCORD_BOT_ADM_CONSTELLATIONS = [20000020]
PRICE_CHECK_HOSTNAME = "evepraisal.com"
LOGGING['handlers']['bot_log_file']= {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(BASE_DIR, 'log/discord_bot.log'),
'formatter': 'verbose',
'maxBytes': 1024 * 1024 * 5,
'backupCount': 5,
}
LOGGING['loggers']['aadiscordbot'] = {'handlers': ['bot_log_file'],'level': 'DEBUG'}
- Add the below lines to
myauth/celery.py
somewhere above the app.autodiscover_tasks...
line
app.conf.task_routes = {'aadiscordbot.tasks.*': {'queue': 'aadiscordbot'}}
- [Docker Only] add
alianceauth-discordbot=version.number
to your requirements.txt and rebuild your containers and restart auth.
- Run migrations
python manage.py migrate
Running Discordbot with Docker
Add a service to run the Discordbot
allianceauth_discordbot:
container_name: allianceauth_discordbot
<<: [ *allianceauth-base ]
restart: on-failure
entrypoint: [ "auth", "run_authbot" ]
- run
docker compose up -d
to start the bot.
[Bare Metal] Running DiscordBot with Supervisor
- Amend your supervisor.conf, correcting paths as required and add
authbot
to the launch group at the end of the conf
[program:authbot]
command=/home/allianceserver/venv/auth/bin/python /home/allianceserver/myauth/manage.py run_authbot
directory=/home/allianceserver/myauth
user=allianceserver
numprocs=1
autostart=true
autorestart=true
stopwaitsecs=600
stdout_logfile=/home/allianceserver/myauth/log/authbot.log
stderr_logfile=/home/allianceserver/myauth/log/authbot.log
[group:myauth]
programs=beat,worker,gunicorn,authbot
priority=999
Enable groups/states/users to utilize the lookup command by adding permissions under corputils | corp stats |
corputils.view_alliance_corpstats
or
aadiscordbot.member_command_access "aadiscordbot | DiscordBot | can access the member commands"
Optional Settings
Built in Cogs
DISCORD_BOT_COGS = [
"aadiscordbot.cogs.about",
"aadiscordbot.cogs.admin",
"aadiscordbot.cogs.members",
"aadiscordbot.cogs.timers",
"aadiscordbot.cogs.auth",
"aadiscordbot.cogs.sov",
"aadiscordbot.cogs.time",
"aadiscordbot.cogs.eastereggs",
"aadiscordbot.cogs.remind",
"aadiscordbot.cogs.reaction_roles",
"aadiscordbot.cogs.services",
"aadiscordbot.cogs.price_check",
"aadiscordbot.cogs.eightball",
"aadiscordbot.cogs.welcomegoodbye",
"aadiscordbot.cogs.models",
"aadiscordbot.cogs.quote",
"aadiscordbot.cogs.prom_export",
"aadiscordbot.cogs.tickets",
"aadiscordbot.cogs.recruit_me",
]
Additional Rate Limiting
DISCORD_BOT_TASK_RATE_LIMITS = {
"send_channel_message_by_discord_id": "100/s",
"send_direct_message_by_discord_id": "1/s",
"send_direct_message_by_user_id": "1/s"
}
Reaction Roles
❗❗❗ This will bypass the Group Leadership/Join Request System: This is intended for open groups but not limited to it! ❗❗❗
The bot is able to run a reaction roles system that is compatible with auth and public users on a discord.
- If a member is part of auth it will do auth syncing of roles
- If a member is not found in auth and the reaction role message has the public flag set it will assign roles to anyone who reacts
How To Reaction Role
-
Setup the inital Message you wish to use buy using the command !rr
- Optional Edit the name and settings of this message in
Admin > Discord Bot > Reaction Role Messages
-
React to the message with the reactions you wish to use.
-
The bot will counter react to the reactions when it creates the binding in auth.
-
Goto Admin > Discord Bot > Reaction Role Bindings
-
Assign the groups you want for each reaction
Messages Admin

Reactions Admin

Integrations
- Statistics
- Adds zkill Monthly/Yearly stats to !lookup
- timezones
- Updates the
time
command to have all timezones configured in auth.
- corptools
where_is
to allow users to find assets quickly
locate
to find all characters and show location and ships
route
to show a route with known JB's
Welcome Messaages
With the WelcomeGoodbye Cog activated, Discordbot will grab a random message from the Welcome or Goodbye Message Model and send it to the Guild System channel
These can be configured in admin under /admin/aadiscordbot/welcomemessage/
and /admin/aadiscordbot/goodbyemessage/
The messages support some string formatting
- `{user_mention} - A Discord @ Mention
- `{guild_name} - The name of the Discord Server
- `{auth_url} - A link to Auth
Welcome {user_mention} to {guild_name}, I hope you enjoy your stay.
You can Authenticate for more access {auth_url}
Private Thread Ticket System
With the aadiscordbot.cogs.tickets
Cog activated, users will be able to issue the /help
command to pick a group to get help from.
The groups available for selection are configurable in the site admin under
Discord Bot > Ticket Cog Configuration
You also need to choose a channel to create the threads in from the site admin Discord Bot > Ticket Cog Configuration
:
- Anyone who can use the
/help
command must have View and Send Message permissions on this channel otherwise they will not be able to see the tickets authbot creates for them
- Authbot must have the permissions to create private threads in this channel
- Authbot must have the permissions to send messages to this channel
Using AA-Discordbot from my project
When using authbot from your application, best practive is to use the provided helper functions for fetching users or checcking permisions to ensure compatability with new versions of the bot, Alliance Auth and potential 3rd party service modules like discord-multiverse
from aadiscordbot.utils.auth import is_user_bot_admin, is_user_authenticated, get_discord_user_id, get_auth_user
More details can be found here
Send Messages
You can use the send_message helper to send a message with text/embed to:
- Discord user_id
- Discord channel_id
- Auth User Model Object
- Auth user_pk
aadiscordbot/tasks.py
Example Usage
from django.contrib.auth.models import User
from django.apps import apps
def discord_bot_active():
return apps.is_installed('aadiscordbot')
if discord_bot_active():
from aadiscordbot.tasks import send_message
from discord import Embed, Color
if discord_bot_active():
usr = User.objects.get(pk=1)
msg = "Channel ID Tests"
e = Embed(title="Channel ID Tests!",
description="This is a Test Embed.\n\n```Discord Channel ID```",
color=Color.yellow())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(channel_id=639252062818926642, embed=e)
send_message(channel_id=639252062818926642, message=msg)
send_message(channel_id=639252062818926642, message=msg, embed=e)
msg = "User ID Tests"
e = Embed(title="User ID Tests!",
description="This is a Test Embed.\n\n```Discord User ID```",
color=Color.nitro_pink())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(user_id=318309023478972417, embed=e)
send_message(user_id=318309023478972417, message=msg)
send_message(user_id=318309023478972417, message=msg, embed=e)
msg = "Auth User Model Tests"
e = Embed(title="Auth User Model Tests!",
description="This is a Test Embed.\n\n```Auth User Model```",
color=Color.dark_orange())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(user=usr, embed=e)
send_message(user=usr, message=msg)
send_message(user=usr, message=msg, embed=e)
msg = "Auth User PK Tests"
e = Embed(title="Auth User PK Tests!",
description="This is a Test Embed.\n\n```Auth User PK```",
color=Color.brand_green())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(user_pk=1, embed=e)
send_message(user_pk=1, message=msg)
send_message(user_pk=1, message=msg, embed=e)
msg = "All Together Tests"
e = Embed(title="All Together Tests!",
description="This is a Test Embed.\n\n```All Together```",
color=Color.blurple())
e.add_field(name="Test Field 1", value="Value of some kind goes here")
send_message(channel_id=639252062818926642,
user_id=318309023478972417,
user=User.objects.get(pk=1),
message=msg,
embed=e)
Registering 3rd Party Cogs (Handling Commands)
In auth_hooks.py
, define a function that returns an array of cog modules, and register it as a discord_cogs_hook
:
@hooks.register('discord_cogs_hook')
def register_cogs():
return ["yourapp.cogs.cog_a", "yourapp.cogs.cog_b"]
Running custom bot context tasks
Create your async task, the function must have a bot instance as its first arg, otherwise you are fine to use any args/kwargs
Basic example task and how to run it
async def send_configuration_to_log(bot, message, commands=False):
logger.error(f"{bot.user} {message} - (commands: {commands})")
logger.error(f"Guilds: {len(bot.guilds)}")
logger.error(f"Users: {len(bot.users)}")
Call the your task by using the shim task. Source and the bot side async context shown here
from aadiscordbot.tasks import run_task_function
run_task_function.delay(
"aadiscordbot.tests.task_tests.send_configuration_to_log",
["TESTING a custom function!"],
{"commands":True}
)
you will need to manage your own error handling. but TLDR these run just like any other celery task. you can also use apply_async
and countdown
to delay the running of the task.
Optional Settings continued
Isolate AuthBot from Auth's Discord Service
AUTHBOT_DISCORD_APP_ID = 'App ID for dedicated bot'
AUTHBOT_DISCORD_BOT_TOKEN = 'Token for dedicated bot'
Issues
Please remember to report any aa-discordbot related issues using the issues on this repository.
Troubleshooting
Py-Cord and discord.py fighting in venv
Problem:
Something has gone funny with my venv after i installed another app that wanted discord.py
Reason:
This is due to the Py-cord lib sharing the discord
namespace. Py-Cord is however a drop in replacement. So no issues should arise from using it over the now legacy discord.py lib. YMMV
Fix:
- Uninstall
discord.py
by running pip uninstall discord.py
with your venv active.
- Reinstall
py-cord
by running pip install -U py-cord==2.0.0b3
with your venv active.
- Approach the dev from the app that overrode your py-cord to update to a maintained lib.