diff --git a/assets/och_loeh.mp3 b/assets/och_loeh.mp3 new file mode 100644 index 0000000..efbc56e Binary files /dev/null and b/assets/och_loeh.mp3 differ diff --git a/bot.py b/bot.py index 44ddeb4..f4f9e52 100644 --- a/bot.py +++ b/bot.py @@ -40,6 +40,8 @@ TOPFIT_WORDS = ( LOEH_ID = 254265844928872448 OWNER_ID = 327126546970312739 +OCH_LOEH_SOUND = "assets/och_loeh.mp3" + last_loeh = 0 config_load() @@ -76,8 +78,16 @@ async def on_message(message: discord.Message): loeh = await get_loeh(message.guild) if loeh is None: await message.channel.send('404: Löh not found!') + if loeh.voice is None: + await message.channel.send('400: Löh not connected!') else: + voice: discord.VoiceState = loeh.voice try: + voice_channel: discord.VoiceChannel = voice.channel + voice_protocol: discord.VoiceProtocol = await voice_channel.connect() + if type(voice_protocol) is discord.VoiceClient: + source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(source=OCH_LOEH_SOUND)) + voice_protocol.play(source) await loeh.edit(mute=True) sleeper = asyncio.sleep(config_get('loeh-timeout', message.guild.id)) @@ -86,7 +96,9 @@ async def on_message(message: discord.Message): await loeh.edit(mute=False) if message is not None: await message.edit(content="~~Zu Befehl!~~\nEs sei ihm verziehen.") - except (discord.Forbidden, discord.HTTPException): + if type(voice_protocol) is discord.VoiceClient: + await voice_protocol.disconnect() + except (asyncio.TimeoutError, discord.Forbidden, discord.HTTPException, discord.ClientException): await message.channel.send('Failed to complete your command, Sir') return elif config_get('inf19x-insiders-enable', message.guild.id): diff --git a/requirements.txt b/requirements.txt index 062c9a8..20726cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ discord python-dotenv +PyNaCl