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.""" """Main module."""
import random import random
from time import sleep
import discord import discord
from discord.ext import commands from discord.ext import commands
@ -23,10 +24,12 @@ class Mybot(commands.Cog):
await ctx.guild.voice_client.disconnect() await ctx.guild.voice_client.disconnect()
@commands.command() @commands.command()
async def benjamin(self, ctx): async def welcome(self, ctx):
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio("/tmp/Benjamin_Prejent.mp3")) 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) 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') @commands.command(help='check if bot always online')
async def ping(self, message): async def ping(self, message):
@ -88,14 +91,15 @@ def main():
@bot.event @bot.event
async def on_voice_state_update(member,before,after): async def on_voice_state_update(member,before,after):
if "BFlow" in member.name:
if before.channel is None and after.channel: if before.channel is None and after.channel:
for channel in bot.get_all_channels(): for channel in bot.get_all_channels():
if channel.name == "général": if channel.name == "général":
current_chan = channel current_chan = channel
ctx = bot.get_context(current_chan.last_message) ctx = await bot.get_context(current_chan.last_message)
benjamin = bot.get_command('benjamin') ctx.message.author = member
await benjamin.invoke(ctx) welcome = bot.get_command('welcome')
sleep(2)
await welcome.invoke(ctx)
bot.add_cog(Mybot(bot)) bot.add_cog(Mybot(bot))
bot.run(token) bot.run(token)