async def cls(self, context): response = await context.send( embed=create_embed({ 'title': 'Clearing terminal', 'color': discord.Color.gold(), })) try: os.system('cls') await response.edit( embed=create_embed({ 'title': 'Terminal cleared', 'color': discord.Color.green(), })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not clear terminal', 'color': discord.Color.red(), }, { 'Error Message': error_message, })) print(f'Could not clear terminal') print(error_message)
async def run(self, context, *, code): response = await context.send(embed=create_embed( { 'title': 'Running code...', 'color': discord.Color.gold(), }, { 'Code': code, })) try: exec(code) await response.edit(embed=create_embed( { 'title': 'Ran code', 'color': discord.Color.green(), }, { 'Code': code, })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not run code', 'color': discord.Color.red(), }, { 'Error Message': error_message, 'Code': code, })) print(f'ERROR: Could not run code {code}') print(error_message)
async def update(context): response = await context.send( embed=create_embed({ 'title': 'Updating bot...', 'color': discord.Color.gold(), })) try: for extension in EXTENSIONS: client.reload_extension(f'cogs.{extension}') await response.edit(embed=create_embed({ 'title': 'Updated bot', 'color': discord.Color.green(), })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not update bot', 'color': discord.Color.red(), }, { 'Error Message': error_message, })) print('ERROR: Could not update bot') print(error_message)
async def on_command_error(self, context, error): if isinstance(error, commands.NoPrivateMessage): await context.send(embed=create_embed({ 'title': f'Commands must be used in servers', 'color': discord.Color.red() })) elif isinstance(error, commands.PrivateMessageOnly): await context.send(embed=create_embed({ 'title': f'Commands must be used in DM\'s', 'color': discord.Color.red() })) elif isinstance(error, commands.MissingPermissions) or isinstance( error, commands.CheckFailure): await context.send(embed=create_embed({ 'title': f'You do not have permission to run this command', 'color': discord.Color.red() })) elif isinstance(error, commands.BadArgument) or isinstance( error, commands.MissingRequiredArgument): await context.send(embed=create_embed({ 'title': f'Incorrect syntax', 'color': discord.Color.red() })) elif isinstance(error, commands.DisabledCommand): await context.send(embed=create_embed({ 'title': f'Command disabled', 'color': discord.Color.red() }))
async def serverinfo(self, context): guild = context.guild response = await context.send( embed=create_embed({ 'title': f'Loading server info for {guild.name}', 'color': discord.Color.gold() })) try: humans = len(list(filter(lambda u: not u.bot, guild.members))) bots = len(list(filter(lambda u: u.bot, guild.members))) online = len( list(filter(lambda u: str(u.status) == 'online', guild.members))) idle = len( list(filter(lambda u: str(u.status) == 'idle', guild.members))) dnd = len( list(filter(lambda u: str(u.status) == 'dnd', guild.members))) offline = len( list( filter(lambda u: str(u.status) == 'offline', guild.members))) await response.edit(embed=create_embed( { 'title': f'{guild.name} server info', 'thumbnail': guild.icon_url, 'inline': True, }, { 'Name': guild.name, 'ID': guild.id, 'Server Created': guild.created_at, 'Owner': guild.owner.mention, 'Region': guild.region, 'Invites': len(await guild.invites()), 'Member Count': guild.member_count, 'Members': f'Γ°ΕΈΛβ¬ {humans} Γ°ΕΈΒ€β {bots}', 'Ban Count': len(await guild.bans()), 'Member Statuses': f'Γ°ΕΈΕΈΒ© {online} Γ°ΕΈΕΈΒ¨ {idle} Γ°ΕΈΕΈΒ₯ {dnd} Γ’Β¬Ε {offline}', 'Category Count': len(guild.categories), 'Channel Count': len(guild.channels), 'Text Channel Count': len(guild.text_channels), 'Voice Channel Count': len(guild.voice_channels), 'Emoji Count': len(guild.emojis), 'Role Count': len(guild.roles) })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not retrieve server info for {guild.name}', 'color': discord.Color.red() }, {'Error Message': error_message})) print(f'ERROR: Could not retrieve server info for {guild.name}') print(error_message)
async def say(self, context, *, message: str): response = await context.send( embed=create_embed({ 'title': f'Saying {message}...', 'color': discord.Color.gold() })) try: user_voice = context.author.voice if not user_voice: await response.edit( embed=create_embed({ 'title': 'You are not in a voice channel', 'color': discord.Color.red() })) return voice_channel = user_voice.channel if not voice_channel: await response.edit( embed=create_embed({ 'title': 'You are not in a voice channel', 'color': discord.Color.red() })) return voice_client = context.voice_client if voice_client and voice_client.channel != voice_channel: await voice_client.disconnect() if not voice_client or voice_client.channel != voice_channel: voice_client = await voice_channel.connect() voice_file = create_voice_file('Gamer Chill Bot Joined') voice_client.stop() voice_client.play(discord.FFmpegPCMAudio(voice_file)) await asyncio.sleep(MP3(voice_file).info.length + 1) voice_file = create_voice_file(message) voice_client.stop() voice_client.play(discord.FFmpegPCMAudio(voice_file)) await response.edit( embed=create_embed({ 'title': f'Said {message}', 'color': discord.Color.green() })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not say {message}', 'color': discord.Color.red() }, { 'Error Message': error_message, })) print('ERROR: Could not say {message}') print(error_message)
async def help(self, context): response = await context.send( embed=create_embed({ 'title': f'Loading commands...', 'color': discord.Color.gold() })) try: pages = [] current_page = 0 for category, commands in COMMANDS.items(): pages.append( create_embed({ 'title': category, 'inline': True, }, commands)) await response.edit(embed=pages[current_page]) while True: await response.add_reaction(BACK_EMOJI) await response.add_reaction(NEXT_EMOJI) reaction, user = await wait_for_reaction( self.client, context, [BACK_EMOJI, NEXT_EMOJI], 60) if str(reaction.emoji) == NEXT_EMOJI: if current_page + 1 >= len(pages): current_page = len(pages) - 1 else: current_page += 1 elif str(reaction.emoji) == BACK_EMOJI: if current_page == 0: current_page = 0 else: current_page -= 1 if context.guild: await response.edit(embed=pages[current_page]) await response.remove_reaction(reaction.emoji, user) else: response = await context.send(embed=pages[current_page]) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not load commands', 'color': discord.Color.red() }, {'Error Message': error_message})) print('ERROR: Could not load commands') print(commands)
async def on_member_remove(self, member: discord.Member): guild_data = get_guild_data(member.guild.id) if guild_data['join_channel']: channel = member.guild.get_channel(guild_data['join_channel']) if channel: await channel.send( embed=create_embed({'title': f'{member.name} left'}))
async def info(self, context): response = await context.send( embed=create_embed({ 'title': 'Loading bot info...', 'color': discord.Color.gold() })) try: uptime = round(time.time() - self.uptime) uptime_text = format_time(uptime) ping = round(self.client.latency * 1000) invite_url = discord.utils.oauth_url( client_id=CLIENT_ID, permissions=discord.Permissions(8)) connected_servers = 0 members_watching = 0 user_ids = [] for guild in self.client.guilds: connected_servers += 1 for member in guild.members: members_watching += 1 if not member.id in user_ids: user_ids.append(member.id) users_watching = len(user_ids) await response.edit(embed=create_embed( { 'title': 'Invite', 'url': invite_url, 'inline': True, }, { 'Ping': f'{ping} ms', 'Uptime': uptime_text, 'Connected Servers': connected_servers, 'Users Watching': members_watching, 'Unique Users Watching': users_watching })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not load bot info', 'color': discord.Color.red() }, {'Error Message': error_message})) print(f'Cannot load bot info') print(error_message)
async def randomperson(self, context): response = await context.send( embed=create_embed({ 'title': f'Choosing random person...', 'color': discord.Color.gold() })) try: random_member = random.choice(context.guild.members) await response.edit(embed=create_embed({'title': random_member})) except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not choose a random person', 'color': discord.Color.red() }, {'Error Message': error_message})) print('ERROR: Could not choose random person') print(error_message)
async def viewsettings(self, context): response = await context.send( embed=create_embed({ 'title': 'Loading settings...', 'color': discord.Color.gold() })) try: guild_data = get_guild_data(context.guild.id) format_guild_data = {} for name, value in guild_data.items(): if name in ['join_channel']: channel = context.guild.get_channel(value) format_guild_data[ name] = channel and channel.mention or 'None' elif name in ['meme_channels']: if len(value) == 0: format_guild_data[name] = 'None' continue formatted_channels = [] for channel_id in value: channel = context.guild.get_channel(channel_id) if channel_id: formatted_channels.append(channel.mention) format_guild_data[name] = ' '.join( formatted_channels) or 'None' print(formatted_channels) print(format_guild_data[name]) await response.edit(embed=create_embed({ 'title': 'Settings', }, format_guild_data)) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not load settings', 'color': discord.Color.red() }, {'Error Message': error_message})) print('Could not load settings') print(error_message)
async def leave(self, context): response = await context.send( embed=create_embed({ 'title': 'Leaving the voice channel...', 'color': discord.Color.gold() })) try: voice_channel_name = None voice_client = context.voice_client if voice_client and voice_client.channel: voice_file = create_voice_file('Gamer Chill Bot is Leaving') voice_client.stop() voice_client.play(discord.FFmpegPCMAudio(voice_file)) await asyncio.sleep(MP3(voice_file).info.length) voice_channel_name = voice_client.channel.name await voice_client.disconnect() else: await response.edit( embed=create_embed({ 'title': 'Bot is not in a voice channel', 'color': discord.Color.red() })) return await response.edit( embed=create_embed({ 'title': f'Left {voice_channel_name}', 'color': discord.Color.green() })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not leave the voice channel', 'color': discord.Color.red() }, {'Error Message': error_message})) print('ERROR: Could not leave VC') print(error_message)
async def roll(self, context, max_number: int = 6): response = await context.send( embed=create_embed({ 'title': f'Rolling a die of {max_number}', 'color': discord.Color.gold() })) try: random_number = random.randint(1, max_number) await response.edit(embed=create_embed({ 'title': random_number, })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not roll a die of {max_number}', 'color': discord.Color.red() }, {'Error Message': error_message})) print('ERROR: Could not roll a dice') print(error_message)
async def getmeme(self, context, amount: int = 1): try: if context.guild: guild_data = get_guild_data(context.guild.id) if not context.channel.id in guild_data['meme_channels']: await context.send( embed=create_embed({ 'title': 'Command banned in this channel', 'color': discord.Color.red(), })) return if random.randint(1, VERY_MAX_MEMES_CHANCE) == 1: await context.send('SUCK ON THIS ETHAN @here') amount = VERY_MAX_MEMES else: if amount > MAX_MEMES: amount = MAX_MEMES for _ in range(amount): while True: meme = await get_meme() if meme in self.recent_memes: continue self.recent_memes.append(meme) if len(self.recent_memes) > 10: self.recent_memes.pop(0) await context.send(meme) break except Exception as error_message: await context.send(embed=create_embed( { 'title': f'Could not retrieve meme', 'color': discord.Color.red() }, {'Error Message': error_message})) print('Could not retrieve meme') print(error_message)
async def eightball(self, context, *, question: str): response = await context.send( embed=create_embed({ 'title': 'Loading response...', 'color': discord.Color.gold() })) try: answer = random.choice(EIGHTBALL_RESPONSES) await response.edit(embed=create_embed({'title': answer})) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not load response', 'color': discord.Color.red() }, { 'Error Message': error_message, 'Question': question, })) print('ERROR: Could not roll 8ball') print(error_message)
async def on_member_join(self, member: discord.Member): if not member.id in self.whitelisted: try: await member.send(embed=create_embed({ 'title': 'You are not whitelisted to join the server', 'description': 'Contact an administrator to be whitelisted', 'color': discord.Color.red() })) except: pass await member.kick() else: self.whitelisted.remove(member.id)
async def restart(self, context): response = await context.send( embed=create_embed({ 'title': f'Are you sure you want to restart the bot?', 'color': discord.Color.gold() })) await response.add_reaction(CHECK_EMOJI) reaction, user = await wait_for_reaction(self.client, context, CHECK_EMOJI, 30) if reaction: await response.edit( embed=create_embed({ 'title': 'Restarting bot...', 'color': discord.Color.green() })) sys.exit() else: await response.edit(embed=create_embed({ 'title': f'You did not respond in time', 'color': discord.Color.red() }))
async def join(self, context): response = await context.send( embed=create_embed({ 'title': 'Joining the voice channel...', 'color': discord.Color.gold() })) try: user_voice = context.author.voice if not user_voice: await response.edit( embed=create_embed({ 'title': 'You are not in a voice channel', 'color': discord.Color.red() })) return voice_channel = user_voice.channel if not voice_channel: await response.edit( embed=create_embed({ 'title': 'You are not in a voice channel', 'color': discord.Color.red() })) return voice_client = context.voice_client if voice_client and voice_client.channel != voice_channel: await voice_client.disconnect() elif voice_client and voice_client.channel == voice_channel: await response.edit( embed=create_embed({ 'title': 'Bot is already connected to the voice channel', 'color': discord.Color.red() })) return voice_client = await voice_channel.connect() voice_file = create_voice_file('Gamer Chill Bot Joined') voice_client.stop() voice_client.play(discord.FFmpegPCMAudio(voice_file)) await response.edit( embed=create_embed({ 'title': f'Joined {voice_channel}', 'color': discord.Color.green() })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not join the voice channel', 'color': discord.Color.red() }, {'Error Message': error_message})) print('ERROR: Could not join VC') print(error_message)
async def impersonate(self, context, member: discord.Member, channel: discord.TextChannel, *, message: str): response = await context.send( embed=create_embed({ 'title': 'Impersonaitng user...', 'color': discord.Color.gold() })) try: if not channel.permissions_for(context.author).send_messages: await response.edit( embed=create_embed({ 'title': f'You cannot talk in {channel}', 'color': discord.Color.red() })) return webhook = await channel.create_webhook(name=member.name) await webhook.send(message, username=member.name, avatar_url=member.avatar_url) await webhook.delete() await response.edit(embed=create_embed( { 'title': f'Impersonated {member} in {channel}', 'color': discord.Color.green() }, {'Message': message})) except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not impersonate {member.name}', 'color': discord.Color.red() }, {'Error Message': error_message})) print(f'ERROR: Could not impersonate {member.name}') print(error_message)
async def reload(context, extension): response = await context.send( embed=create_embed({ 'title': f'Reloading {extension}...', 'color': discord.Color.gold(), })) try: client.reload_extension(f'cogs.{extension}') await response.edit(embed=create_embed({ 'title': f'Reloaded {extension}', 'color': discord.Color.green(), })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not reload {extension}', 'color': discord.Color.red(), }, { 'Error Message': error_message, })) print(f'ERROR: Could not reload extension {extension}') print(error_message)
async def whitelist(self, context, user_id=None): response = await context.send(embed=create_embed({ 'title': f'Whitelisting {user_id}', 'color': discord.Color.gold() })) try: if user_id: user_id = int(user_id) if user_id in self.whitelisted: self.whitelisted.remove(user_id) await response.edit(embed=create_embed({ 'title': f'Blacklisted {user_id}', 'color': discord.Color.green() })) elif context.guild.get_member(user_id): await response.edit(embed=create_embed({ 'title': f'{user_id} is already in the server', 'color': discord.Color.red() })) else: self.whitelisted.append(user_id) await response.edit(embed=create_embed({ 'title': f'Whitelisted {user_id}', 'color': discord.Color.green() })) else: users = ', '.join([str(id) for id in self.whitelisted]) or 'None' await response.edit(embed=create_embed({ 'title': f'Whitelisted Users: {users}' })) except ValueError: await response.edit(embed=create_embed({ 'title': f'{user_id} is not a number', 'color': discord.Color.red() })) except Exception as error_message: await response.edit(embed=create_embed({ 'title': f'Could not whitelist {user_id}', 'color': discord.Color.red() }, { 'Error Message': error_message })) print(f'Could not whitelist {user_id}') print(error_message)
async def find_friends(ctx): if not config.running: config.running = True #await client.change_presence(status = discord.Status.dnd, activity = helper.active_status) await ctx.author.send("Finding you friends... (this will take a while, don't be afraid if I go offline!)") await ctx.send("Running friend analysis... (this will take a while, don't be afraid if I go offline!)") friend_values = await finder.find_friends(ctx.author, ctx.guild, config.dictionary) ordered_list = sorted(friend_values.items(), key = lambda x: x[1], reverse = True) # creates a list of tuples #await client.connect(reconnect=True) await ctx.author.send(embed = helper.create_embed(client.user, ctx.author, config.REPORT_COUNT, ordered_list)) #await client.change_presence(status = discord.Status.online, activity = helper.idle_status) # this line causes an error for some reason (websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1000 (OK), no reason) await ctx.send("Analysis complete!") config.running = False else: await ctx.send("Currently busy!")
async def userinfo(self, context, *, user: discord.Member = None): if not user: user = context.author response = await context.send( embed=create_embed({ 'title': f'Loading user info for {user}...', 'color': discord.Color.gold() })) try: if context.guild: await response.edit(embed=create_embed( { 'title': f'{user}\'s User Info', 'thumbnail': user.avatar_url, }, { 'Account Created': user.created_at.strftime('%m/%d/%y - %I:%M:%S %p'), 'Activity': ', '.join(user.activities) or 'None', 'Boosted Server': user.premium_since and user.premium_since.strftime( '%m/%d/%y - %I:%M:%S %p') or 'No', 'Bot': user.bot and 'Yes' or 'No', 'Device': user.desktop_status and 'Desktop' or user.web_status and 'Website' or user.mobile_status and 'Mobile' or 'Unknown', 'Joined Server': user.joined_at.strftime('%m/%d/%y - %I:%M:%S %p'), 'Messages (Server)': len(await user.history(limit=None).flatten()), 'Nickname': user.nick, 'Pending': user.pending and 'Yes' or 'No', 'Roles': ' '.join([role.mention for role in user.roles]), 'Status': str(user.status).capitalize(), 'User ID': user.id, })) else: await response.edit(embed=create_embed( { 'title': f'{user}\'s User Info', 'thumbnail': user.avatar_url, }, { 'Account Created': user.created_at.strftime('%m/%d/%y - %I:%M:%S %p'), 'Bot': user.bot and 'Yes' or 'No', 'User ID': user.id, 'Mutual Guilds': len(user.mutual_guilds), 'Messages (DM)': len(await user.history(limit=None).flatten()), })) except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not retrieve user info for {user}', 'color': discord.Color.red() }, { 'Error Message': error_message, })) print(f'ERROR: Could not retrieve user info for {user}') print(error_message)
async def set(self, context, name, *, value): response = await context.send( embed=create_embed({ 'title': f'Changing {name} to {value}...', 'color': discord.Color.gold() })) try: guild_data = get_guild_data(context.guild.id) if name in ['join_channel']: if value == 'none': guild_data[name] = None save_guild_data(guild_data) await response.edit( embed=create_embed({ 'title': f'Removed {name}', })) else: channel = get_object(context.guild.text_channels, value) if channel: guild_data[name] = channel.id save_guild_data(guild_data) await response.edit(embed=create_embed({ 'title': f'Changed {name} to {channel.name}', })) else: await response.edit( embed=create_embed({ 'title': f'Could not find channel {value}', 'color': discord.Color.red() })) print(f'Could not find channel {value}') elif name in ['meme_channels']: channel = get_object(context.guild.text_channels, value) if not channel: await response.edit( embed=create_embed({ 'title': f'Could not find channel {value}', 'color': discord.Color.red() })) print(f'Could not find channel {value}') return if channel.id in guild_data[name]: guild_data[name].remove(channel.id) save_guild_data(guild_data) await response.edit( embed=create_embed({ 'title': f'Removed channel #{channel.name}', 'color': discord.Color.green() })) else: guild_data[name].append(channel.id) save_guild_data(guild_data) await response.edit( embed=create_embed({ 'title': f'Added channel #{channel.name}', 'color': discord.Color.green() })) else: await response.edit( embed=create_embed({ 'title': f'{name} is an invalid setting', 'color': discord.Color.red() })) print(f'{name} is an invalid setting') except Exception as error_message: await response.edit(embed=create_embed( { 'title': f'Could not change {name} to {value}', 'color': discord.Color.red() }, {'Error Message': error_message})) print(f'Could not change {name} to {value}') print(error_message)
async def messageleaderboard(self, context): response = await context.send(embed=create_embed({ 'title': 'Loading message leaderboard...', 'description': f'React with {CHECK_EMOJI} to be pinged when the message leaderboard is done. This process could take several minutes or hours depending on the amount of messages in a server.', 'color': discord.Color.gold() })) await response.add_reaction(CHECK_EMOJI) try: members = {} async def get_messages_in_guild(guild): for channel in guild.text_channels: messages = await channel.history(limit=None).flatten() for message in messages: author = message.author if not guild.get_member(author.id): continue if not members.get(author.name): members[author.name] = 1 else: members[author.name] += 1 if context.guild: await get_messages_in_guild(context.guild) else: for guild in self.client.guilds: await get_messages_in_guild(guild) await response.edit(embed=create_embed({ 'title': f'Loading message leaderboard (sorting leaderboard)...', 'description': f'React with {CHECK_EMOJI} to be pinged when the message leaderboard is done', 'color': discord.Color.gold() })) members = sort_dictionary(members, True) members = get_first_n_items(members, MAX_LEADERBOARD_FIELDS) await response.edit(embed=create_embed( { 'title': context.guild and 'Message Leaderboard (Current Server)' or 'Message Leaderboard (All Servers)' }, members)) response2 = await response.channel.fetch_message(response.id) for reaction in response2.reactions: if str(reaction.emoji) == CHECK_EMOJI: users = [] async for user in reaction.users(): if not user.bot: users.append(user.mention) if len(users) > 0: ping = ' '.join(users) await context.send(' '.join(users)) break except Exception as error_message: await response.edit(embed=create_embed( { 'title': 'Could not load message leaderboard', 'color': discord.Color.red() }, {'Error Message': error_message})) print('ERROR: Could not load message leaderboard') print(error_message)