import configparser import discord import os from pathlib import Path client = discord.Client() Config = configparser.ConfigParser() #/home/pi/discord/jar-bot/ ini = Path('/home/pi/discord/jar-bot/count.ini') if not ini.is_file(): f = open("c/home/pi/discord/jar-bot/count.ini", "x") #repl.it #ch_name = 'das-glas-ptr' #pi ch_name = 'das-glas' #-------------------------------------------------------------------------------------------------------- async def dc(vc): while True: if not vc.is_playing(): await vc.disconnect() return #-------------------------------------------------------------------------------------------------------- async def play_coin(name): voicechannel = name.voice.channel if voicechannel != None: vc = await voicechannel.connect() vc.play(discord.FFmpegPCMAudio("/home/pi/discord/jar-bot/coin.mp3")) await dc(vc) #-------------------------------------------------------------------------------------------------------- #coin_plus(message.author.display_name,message.content.count('\U0001FA99')) def coin_plus(name,plus): Config.read(ini) if Config.has_section(name): count = Config.getint(name,'count') count = count + plus Config.set(name,'count',str(count)) else: Config.add_section(name) count = plus Config.set(name,'count',str(count)) with open(ini, 'w') as configfile: Config.write(configfile) #-------------------------------------------------------------------------------------------------------- async def stand_out(chanel): Config.read(ini) stand = list() await chanel.send('Der Stand ist:') for x in Config.sections(): count = Config.getint(x,'count') stand.append([count, x]) stand.sort(reverse=True) for item in stand: if item[0] == "1": await chanel.send(item[1] + ' hat eine Münze in das Glas geworfen') else: await chanel.send(item[1] + ' hat '+ str(item[0]) +' Münzen in das Glas geworfen') with open(ini, 'w') as configfile: Config.write(configfile) #-------------------------------------------------------------------------------------------------------- #\U0001FA99 - coin #\U0001F4B8 - money with wings #\U0001F4B0 - moneybag @client.event async def on_ready(): print('We have logged in as {0.user}'.format(client)) @client.event async def on_message(message): if message.author == client.user: return if message.channel.name == ch_name: if message.content.count('\U0001FA99')>0: if len(message.mentions)>0: await message.add_reaction('\U0001F4B8') for j in message.mentions: coin_plus(j.display_name,message.content.count('\U0001FA99')) else: await message.add_reaction('\U0001F4B0') coin_plus(message.author.display_name,message.content.count('\U0001FA99')) await play_coin(message.author) elif message.content.startswith('!stand'): await message.delete() for x in message.author.roles: if str(x) == "Meh": await stand_out(message.channel) else: await message.delete() #-------------------------------------------------------------------------------------------------------- #repl.it #client.run('ODI4Nzc4MTg0Nzg1OTIwMDIw.YGuh1Q.-MWOKUsNNBOzWFDYHjUtA-7umN0') #pi client.run('ODE1Mzc0MDc0NDU5OTc5ODM2.YDreSA.q494wu3zvinCJ6QiffrWvoUVibc') #--------------------------------------------------------------------------------------------------------