Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- botprefixes = ("?", "!", "/")
- client = Bot(command_prefix = botprefixes, case_insensitive=True)
- client.remove_command('help')
- voicechannelid = 691284883619709102
- def getaudio():
- #Getting all sounds
- allsounds = [sound for sound in os.walk('sounds')]
- allsounds.pop(0)
- sounds = {}
- uncategorizedsounds = {}
- for soundfolder in allsounds:
- foldername = soundfolder[0].split(os.sep)[-1]
- sounds[foldername]=[]
- for sound in soundfolder[2]:
- soundname = sound.replace('.mp3','')
- soundpath = os.path.join(foldername,sound)
- #makes the path work on windows
- if soundpath[0:6] != 'sounds':
- soundpath = os.path.join('sounds',soundpath)
- sounds[foldername].append(soundpath)
- uncategorizedsounds[soundname]=soundpath
- #Creating help command message
- helpmessage = 'Lista cu sunete, toate se scriu dupa comanda !franku\n\n'
- for folder in list(sounds.keys()):
- helpmessage+='{0} - sunet random cu {0}\n'.format(folder)
- for audio in sounds[folder]:
- audioname = audio.split(os.sep)[-1].replace('.mp3','')
- helpmessage+=' {0}\n'.format(audioname)
- helpmessage+='\n'
- helpmessage+='\n!ho, !stop - il opreste'
- return(sounds,uncategorizedsounds,helpmessage)
- @client.event
- async def on_ready():
- await client.change_presence(activity=discord.Game(name='PinkGuy Simulator'))
- print("Logged in as " + client.user.name)
- voicechannel = client.get_channel(voicechannelid) #get voice channel
- Voiceclient = await voicechannel.connect() # connect to voice channel
- sounddata = getaudio()
- Voiceclient.sounds = sounddata[0]
- Voiceclient.uncategorizedsounds = sounddata[1]
- Voiceclient.helpmessage = sounddata[2]
- #If an unrecognized command is used stops from giving out an error
- @client.event
- async def on_command_error(context, error):
- if isinstance(error, CommandNotFound):
- return
- raise error
- @client.command()
- async def franku(context,*argument):
- voice = context.voice_client
- if not argument:
- mp3name = choice(list(voice.uncategorizedsounds.keys()))
- mp3 = voice.uncategorizedsounds[mp3name]
- elif argument[0].lower() in list(voice.sounds.keys()):
- mp3 = choice(voice.sounds[argument[0].lower()])
- elif argument[0].lower() in list(voice.uncategorizedsounds.keys()):
- mp3 = voice.uncategorizedsounds[argument[0].lower()]
- elif argument[0].lower() == 'reload':
- sounddata = getaudio()
- voice.sounds = sounddata[0]
- voice.uncategorizedsounds = sounddata[1]
- voice.helpmessage = sounddata[2]
- await context.send('Sounds loaded')
- return
- else:
- print('audio "{0}" not found'.format(argument[0].lower()))
- return
- if voice.is_playing():
- voice.stop()
- audio = discord.FFmpegPCMAudio(mp3,executable=FfmpegPath)
- voice.play(audio)
- @client.command(aliases=['ho'])
- async def stop(context):
- voice = context.voice_client
- if voice.is_playing():
- voice.stop()
- @client.command()
- async def sunete(context):
- voice = context.voice_client
- await context.send(voice.helpmessage)
- config = configparser.ConfigParser()
- config.read('frankubot.ini')
- FfmpegPath = config['FRANKUBOT']['FfmpegPath']
- client.run(BOTTOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement