Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Created by Preston J.
- Using discord.py on Python 3.6.7
- WingBot is a discord bot that listens for chat commands, and does something in return.
- '''
- import time
- import datetime
- import discord
- import unicodedata
- from discord.ext import commands
- from discord.ext.commands import CommandNotFound
- import asyncio
- if not discord.opus.is_loaded():
- discord.opus.load_opus('opus')
- # WingBot Client Token so the program can communicate with the bot
- TOKEN = ''
- client = commands.Bot(command_prefix = '.')
- players = {} # This dictionary is used so the bot can be used in multiple servers.
- def executed(cmd, user): # This function logs the commands that are executed, who they're executed by, and when they were executed.
- log_f = open('WingBotlog.txt', 'a')
- x = datetime.datetime.now()
- executed = '{} command executed by {} on {}-{}-{} at {}:{}:{}'.format(cmd, user, x.month, x.day, x.year, x.hour, x.minute, x.second)
- log_f.write('\n{} command executed by {} on {}-{}-{} at {}:{}:{}'.format(cmd, user, x.month, x.day, x.year, x.hour, x.minute, x.second))
- log_f.close()
- return executed
- async def chatCommand(message, msg, file, file2, cmd): # This function makes the process of creating chat commands easier.
- if msg != None:
- await client.send_message(message.channel, msg)
- if file != None:
- await client.send_file(message.channel, file)
- if file2 != None:
- await client.send_file(message.channel, file2)
- if cmd != None:
- print(executed(cmd, message.author))
- async def voiceCommand(ctx, message, file, time, cmd):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the voice command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- print(executed(cmd, message.author))
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player(file) # Uses ffmpeg to create a player, however it makes a pop up when it runs.
- player.start()
- time.sleep(float(time))
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- file = open('banlist.txt', 'r')
- banlist = []
- for line in file:
- line = line.strip() # This strips every \n in the textfile when porting the IDs to the list.
- banlist.append(str(line))
- print('Banlist: {}'.format(banlist))
- @client.event
- # When the bot starts up, and is ready to be used on the Discord app, it will notify terminal.
- async def on_ready():
- print('WingBot Starting...')
- print('Ready for Use')
- botservers = []
- for server in client.servers:
- fixedserver = unicodedata.normalize('NFKD', str(server)).encode('ascii','ignore')
- botservers.append(fixedserver)
- print('Servers the bot is in: {}'.format(botservers))
- print('-------------------')
- @client.event
- async def on_command_error(ctx, error): # This takes the useless CommandNotFound error, and prevents shell from printing it.
- if isinstance(error, CommandNotFound):
- return
- @client.event
- async def on_message(message): # When WingBot detects that a message is sent.
- if message.author == client.user: # If the message the bot detects is from the bot itself, it doesn't do anything.
- return
- bruhcommands = ['.bruhhelp', '.bruh', '.saybruh', '.wing', '.duskiewing', '.cole', '.bigbruh',
- '.brucc', '.banfrombot', '.breh', '.tanner', '.kanye', '.verizonbald', '.traffic']
- if message.author.id == '247199003844935680':
- await chatCommand(message, '<@247199003844935680> bot', None, None, None)
- if message.author.id == '205855331178381313':
- await chatCommand(message, '<@205855331178381313> Bald', 'Male04.jpg', None, None)
- if message.content in bruhcommands and message.author.id in banlist:
- await client.send_message(message.channel, 'You are banned from using the bot <@{}>!'.format(message.author.id))
- else:
- # Commands it listens to from the user:
- if message.content == '.bruhhelp': # Using a msg variable because of the long text
- msg = 'Here is a website containing all of the WingBot Commands: https://sites.google.com/view/wingbotcommands/home'
- await chatCommand(message, msg, None, None, 'bruhhelp')
- if message.content == '.bruh':
- await chatCommand(message, '{0.author.mention} is a big bruh.'.format(message), 'bruhmoji.png', None, 'bruh')
- if message.content == '.wing':
- await chatCommand(message, None, 'thewing.jpg', 'wantwing.jpg', 'wing')
- if message.content == '.duskiewing':
- await chatCommand(message, None, 'duskiewing.jpg', None, 'duskiewing')
- if message.content == '.breh':
- file = 'tanbald.png'
- await client.send_file(message.channel, file)
- print(executed('breh', message.author))
- if message.content == '.saybruh':
- print(executed('saybruh', message.author))
- if message.content == '.kanye':
- print(executed('kanye', message.author))
- if message.content == '.tanner':
- print(executed('tanner', message.author))
- if message.content == '.baldverizon':
- print(executed('baldverizon', message.author))
- if message.content == '.banfrombot' and message.author.id == '195341565089153026': # Capn's ID by default
- print(executed('banfrombot', message.author))
- if message.content == '.traffic':
- print(executed('bigbruh', message.author))
- if message.content == '.brucc':
- print(executed('brucc', message.author))
- await client.process_commands(message) #This is used so that on_message events can be checked while commands are checked
- @client.command(pass_context = True)
- async def bigbruh(ctx):
- voiceCommand(ctx, message, 'bigbruh.mp3', '0.5', 'bigbruh')
- @client.command(pass_context = True)
- async def banfrombot(ctx, discid=None):
- global banlist
- adminid = '195341565089153026'
- if discid == None:
- await client.say('Missing required argument: Discord ID.')
- elif ctx.message.author.id == adminid:
- try:
- discid = int(discid)
- if str(discid) in banlist:
- await client.say('(ID {}) is already in the blacklist!'.format(discid))
- else:
- file = open('banlist.txt', 'a')
- file.write('\n{}'.format(discid))
- file.close()
- banlist.append(str(discid))
- await client.say('Added <@{}> to the blacklist.'.format(discid))
- except ValueError:
- await client.say('Must be a valid ID!')
- else:
- await client.say('You do not have permission to use this command!')
- @client.command(pass_context = True)
- async def brucc(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .brucc command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('brucc.mp3')
- player.start()
- time.sleep(25)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- @client.command(pass_context = True)
- async def cole(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .cole command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('cole.mp3')
- player.start()
- time.sleep(5)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- @client.command(pass_context = True)
- async def tanner(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .tanner command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('tanner.wav')
- player.start()
- time.sleep(16)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- @client.command(pass_context = True)
- async def breh(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .breh command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('Breh.wav')
- player.start()
- time.sleep(0.5)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- @client.command(pass_context = True)
- async def baldverizon(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .baldverizon command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('verizon.mp3')
- player.start()
- time.sleep(30)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- @client.command(pass_context = True)
- async def kanye(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .kanye command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('kanye.mp3')
- player.start()
- time.sleep(3)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- @client.command(pass_context = True)
- async def saybruh(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .saybruh command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('bruh.mp3')
- player.start()
- time.sleep(1)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- @client.command(pass_context = True)
- async def traffic(ctx):
- channel = ctx.message.author.voice.voice_channel
- if channel == None: # If the user who sent the .traffic command isn't in a voice channel.
- await client.say('You are not in a voice channel, therefore I cannot run this command.')
- return
- else: # If the user is in a voice channel
- voice = await client.join_voice_channel(channel)
- server = ctx.message.server
- voice_client = client.voice_client_in(server)
- player = voice.create_ffmpeg_player('traffic.mp3')
- player.start()
- time.sleep(7.5)
- await voice_client.disconnect() # Disconnects WingBot from the voice channel.
- # Starts communication to Discord and runs WingBot
- client.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment