From 509b6a6a42bdfd68bba1048d3f8a5c55c267fd16 Mon Sep 17 00:00:00 2001 From: Milka64 Date: Wed, 2 Oct 2019 20:59:23 +0200 Subject: [PATCH] add welcome command --- kabot/kabot/kabot.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/kabot/kabot/kabot.py b/kabot/kabot/kabot.py index e400780..fcbfde6 100644 --- a/kabot/kabot/kabot.py +++ b/kabot/kabot/kabot.py @@ -2,6 +2,7 @@ """Main module.""" import random +from time import sleep import discord from discord.ext import commands @@ -23,10 +24,12 @@ class Mybot(commands.Cog): await ctx.guild.voice_client.disconnect() @commands.command() - async def benjamin(self, ctx): - source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("/tmp/Benjamin_Prejent.mp3")) + async def welcome(self, ctx): + user = ctx.message.author.name + audio_file = random.choice([f for f in os.listdir('/home/mika/kabot/kabot/kabot/Audio/%s/' % user) if f.endswith('.mp3')]) + source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("/home/mika/kabot/kabot/kabot/Audio/%s/%s" % (user,audio_file))) ctx.voice_client.play(source, after=lambda e: print('Player error: %s' % e) if e else None) - await ctx.send('Now playing') + return @commands.command(help='check if bot always online') async def ping(self, message): @@ -88,14 +91,15 @@ def main(): @bot.event async def on_voice_state_update(member,before,after): - if "BFlow" in member.name: - if before.channel is None and after.channel: - for channel in bot.get_all_channels(): - if channel.name == "général": - current_chan = channel - ctx = bot.get_context(current_chan.last_message) - benjamin = bot.get_command('benjamin') - await benjamin.invoke(ctx) + if before.channel is None and after.channel: + for channel in bot.get_all_channels(): + if channel.name == "général": + current_chan = channel + ctx = await bot.get_context(current_chan.last_message) + ctx.message.author = member + welcome = bot.get_command('welcome') + sleep(2) + await welcome.invoke(ctx) bot.add_cog(Mybot(bot)) bot.run(token)