add welcome command

This commit is contained in:
Milka64 2019-10-02 20:59:23 +02:00
parent 34d063dfeb
commit 509b6a6a42

View file

@ -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)
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)