Discord: Roles cannot be created, missing guild ID in URI
Created by: marandus
The Discord integration fails to create and update roles on the server. The AllianceAuth instance was setup yesterday, so it uses the most current code base.
The following errors are printed to the notifications of the superuser (pseudonymized usernames and stuff):
Discord group sync failed for username, retrying in 10 mins
Traceback (most recent call last):
File "/opt/python_venv/allianceserver/allianceauth/services/tasks.py", line 425, in update_discord_groups
DiscordOAuthManager.update_groups(authserviceinfo.discord_uid, groups)
File "/opt/python_venv/allianceserver/allianceauth/services/managers/discord_manager.py", line 194, in update_groups
group_ids = [DiscordOAuthManager.__group_name_to_id(DiscordOAuthManager._sanitize_groupname(g)) for g in groups]
File "/opt/python_venv/allianceserver/allianceauth/services/managers/discord_manager.py", line 150, in __group_name_to_id
DiscordOAuthManager.__create_group(name)
File "/opt/python_venv/allianceserver/allianceauth/services/managers/discord_manager.py", line 187, in __create_group
role = DiscordOAuthManager.__generate_role()
File "/opt/python_venv/allianceserver/allianceauth/services/managers/discord_manager.py", line 167, in __generate_role
r.raise_for_status()
File "/opt/python_venv/allianceserver/local/lib/python2.7/site-packages/requests/models.py", line 862, in raise_for_status
raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: NOT FOUND for url: https://discordapp.com/api/guilds//roles
As can be seen the call to Discord is made without the guild ID put into the string, which seems to be the reason for this bug. However, I took a look at the code line (and surrounding code) that was reported, the guild ID is actually concatenated into the URI:
@staticmethod
def __generate_role():
custom_headers = {'accept': 'application/json', 'authorization': 'Bot ' + settings.DISCORD_BOT_TOKEN}
path = DISCORD_URL + "/guilds/" + str(settings.DISCORD_GUILD_ID) + "/roles"
r = requests.post(path, headers=custom_headers)
logger.debug("Received status code %s after generating new role." % r.status_code)
r.raise_for_status()
return r.json()
I don't know much about python so I am unable to fix this, so please take a look into it.