diff --git a/bot/commands.py b/bot/commands.py index 9c7d1a7..693d496 100644 --- a/bot/commands.py +++ b/bot/commands.py @@ -1,4 +1,5 @@ import discord +from io import StringIO from discord.ext import commands from django.contrib.auth.models import User from django.db import close_old_connections @@ -262,7 +263,7 @@ class Commands(commands.Cog): @commands.command() async def sync(self, ctx): def sync_player(player): - for member in ctx.get_guild(self.bot.sync_guild).members: + for member in ctx.guild.members: name = member.nick if member.nick else member.name if player.username.lower() == name.lower(): player.discord_id = member.id @@ -270,18 +271,19 @@ class Commands(commands.Cog): return True return False # Attempt to sync users - if not self.bot.sync_guild: - self.bot.discord_message(ctx.author, "DISCORD_SYNC_GUILD must be defined to sync players to Discord") - return need_sync = Player.objects.filter(discord_id__isnull=True) need_sync_count = need_sync.count() - synced = 0 + synced = [] + not_synced = [] if need_sync_count > 0: for ns in need_sync: if sync_player(ns): - synced += 1 - self.bot.discord_message(ctx.author, "Successfully synced {}/{} players.".format(synced, need_sync_count)) - + synced.append(ns.username) + else: + not_synced.append(ns.username) + txt = "Synced\n\t{}\n\nNot Synced\n\t{}".format('\n\t'.join(synced), '\n\t'.join(not_synced)) + attach = discord.File(fp=StringIO(txt), filename="sync.txt") + await ctx.channel.send(content="Successfully synced {}/{} players.".format(len(synced), need_sync_count), file=attach) def setup(bot): diff --git a/bot/discord.py b/bot/discord.py index ffe08bc..4895dc1 100644 --- a/bot/discord.py +++ b/bot/discord.py @@ -22,11 +22,12 @@ class Discord(commands.Bot): auth_roles = getattr(settings, 'DISCORD_BOT_ROLES', []) superuser_roles = getattr(settings, 'DISCORD_SUPERUSER_ROLES', []) error_users = getattr(settings, 'DISCORD_ERROR_USERS', []) - sync_guild = getattr(settings, 'DISCORD_SYNC_GUILD', '') def __init__(self, token): + intents = discord.Intents.default() + intents.members = True super().__init__(command_prefix=self.prefix, description=description, case_insensitive=True, help_command=None, - activity=discord.Game(name=self.discord_game)) + activity=discord.Game(name=self.discord_game), intents=intents) self.token = token self.load_extension("minecraft_manager.bot.commands") @@ -92,5 +93,5 @@ class Discord(commands.Bot): print(e) logger.info('Bot encountered the following unhandled exception %s', e) finally: - loop.run_until_complete(self.logout()) + loop.run_until_complete(self.close()) logger.info("Bot shutting down...") diff --git a/templates/minecraft_manager/player_info.html b/templates/minecraft_manager/player_info.html index b9dd13d..3ca0bfe 100644 --- a/templates/minecraft_manager/player_info.html +++ b/templates/minecraft_manager/player_info.html @@ -7,6 +7,7 @@

UUID: {{ player.uuid }}

+

Discord ID: {% if player.discord_id %}{{ player.discord_id }} {% else %}N/A{% endif %}

{% if player.auth_user %}

Connected User: {{ player.auth_user.username }}

{% endif %}