From fb98ae77bf3014e4d39dc029e59772fb5ebb7db7 Mon Sep 17 00:00:00 2001 From: jweigele Date: Sun, 13 Jun 2021 15:14:24 -0700 Subject: [PATCH] Some debug prints, update discord API section for intents, fix bug in setting voice to None --- grahbot.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/grahbot.py b/grahbot.py index 173adb3..1b7d938 100755 --- a/grahbot.py +++ b/grahbot.py @@ -47,12 +47,19 @@ class GrahState(object): def set_voice(self, guild, voice): + print('Setting voice for guild {} to {}'.format(guild, voice)) self.set_voice_by_id(guild.id, voice) def set_voice_by_id(self, guild_id, voice): - self.data['guild'][str(guild_id)] = voice.channel.id - if not self.voice[str(guild_id)]: - self.voice[str(guild_id)] = voice + if voice is None: + if str(guild_id) in self.data['guild']: + del self.data['guild'][str(guild_id)] + if str(guild_id) in self.voice: + del self.voice[str(guild_id)] + else: + self.data['guild'][str(guild_id)] = voice.channel.id + if not self.voice[str(guild_id)]: + self.voice[str(guild_id)] = voice self.save() @@ -151,7 +158,7 @@ class GrahDiscordBot(discord.Client, HornClient): else: log.debug('Received a horn not for us: {}'.format(msg.body)) - def __init__(self, config): + def __init__(self, config, intents=None): self.config = config self.player = None self.used = [] @@ -161,7 +168,7 @@ class GrahDiscordBot(discord.Client, HornClient): #self.horn_client = HornClient('config-piege.json') HornClient.__init__(self, config) self.rabbit = self.loop.create_task(self.rabbit_connect()) - discord.Client.__init__(self, loop=self.loop) + discord.Client.__init__(self, loop=self.loop, intents=intents) self.loop_forever() def terminate_all(self, guild): @@ -287,7 +294,7 @@ class GrahDiscordBot(discord.Client, HornClient): guild = discord.utils.get(self.guilds, id=guild_id) if self.state.get_voice(guild): self.terminate_all(guild=guild) - self.state.get_voice(guild).play(discord.FFmpegPCMAudio(filename)) + self.state.get_voice(guild).play(discord.FFmpegOpusAudio(filename)) #self.player.start() else: log.debug('Was asked to play {} but no voice channel'.format(filename)) @@ -352,6 +359,10 @@ class GrahDiscordBot(discord.Client, HornClient): def member_guild_list(self, member): + for x in self.guilds: + for member in x.members: + print('Guild {} Member {}'.format(x, member)) + #print(x.members) return [x for x in self.guilds if member in x.members] def contextual_guild(self, message): @@ -449,6 +460,7 @@ class GrahDiscordBot(discord.Client, HornClient): await message.channel.send('Too many guilds!!!\n{}'.format('\n'.join([str(x) for x in guilds]))) return elif len(guilds) == 1: + print('Guild is {}'.format(guilds[0])) guild = guilds[0] func = self.get_command_func(potential_command) @@ -465,4 +477,6 @@ class GrahDiscordBot(discord.Client, HornClient): if __name__ == '__main__': config = json.load(open('{}/config.json'.format(PERSISTENT_DIR), 'r')) - bot = GrahDiscordBot(config) + intents = discord.Intents.default() + intents.members = True + bot = GrahDiscordBot(config, intents=intents) -- 2.30.2