def load_extension(extension): ext = extension.replace('/', '.') try: bot.load_extension(ext) con.log(f"{ext} loaded.") except Exception as e: con.log(f"Couldn't load {ext}: {e}")
async def statuses(self): data = await hypixel.counts() if data['success'] != True: con.log(f"Couldn't set status.\nSuccess: {data['success']}") if logchannel is not None: channel = self.bot.get_channel(logchannel) if channel is not None: embed = discord.Embed( title=f"Couldn't set custom status.", description=f"```\nAPI Success: {data['success']}\n```", color=0xff0000) try: await channel.send(embed=embed) except discord.Forbidden: raise ValueError( "The bot does not have permissions to send messages in the logchannel specified in config.ini." ) else: raise ValueError( "The logchannel specified in config.ini is not visible to the bot, or does not exist." ) await self.bot.change_presence( status=discord.Status.online, activity=discord.Activity( type=discord.ActivityType.streaming, name="on the Hypixel Network.", url='https://www.twitch.tv/technoblade')) else: await self.bot.change_presence( status=discord.Status.online, activity=discord.Activity( type=discord.ActivityType.streaming, name=f"{utils.comma(data['playerCount'])} player's stats.", url='https://www.twitch.tv/technoblade'))
async def stop(self, ctx): con.log(f'{ctx.author.id} is attempting to remotely shutdown the bot...') await ctx.send('Stopping the bot...') if logchannel is not None: channel = self.bot.get_channel(logchannel) if channel is not None: embed = discord.Embed(title=f"Bot shutting down", description=f"```\n{ctx.author} is remotely shutting down the bot.\n```", color=0xff0000) try: await channel.send(embed=embed) except discord.Forbidden: raise ValueError("The bot does not have permissions to send messages in the logchannel specified in botconfig.ini.") else: raise ValueError("The logchannel specified in botconfig.ini is not visible to the bot, or does not exist.") await self.bot.logout()
async def reload(self, ctx, *, cog: str): try: self.bot.unload_extension(cog) con.log(f' Unloaded extension {cog}.') self.bot.load_extension(cog) con.log(f' Loaded extension {cog}.') con.log(f'Successfully reloaded extension {cog}.') except Exception as e: embed = discord.Embed(title='Error', description=str(e), color=0xff0000) await ctx.send(embed=embed) con.log(f"Couldn't reload extension {cog}: {e}") else: color=random.randint(1, 16777215) embed = discord.Embed(title='Success', description=f'Successfully reloaded extension {cog}', color=color) await ctx.send(embed=embed)
async def unload(self, ctx, *, cog: str): con.log(f'{ctx.author.name} ({ctx.author.id}) is attempting to unload extension {cog}...') try: self.bot.unload_extension(cog) con.log(f'Successfully unloaded extension {cog}.') except Exception as e: embed = discord.Embed(title='Error', description=str(e), color=0xff0000) await ctx.send(embed=embed) con.log(f"Couldn't unload extension {cog}: {e}") else: color=random.randint(1, 16777215) embed = discord.Embed(title='Success', description=f'Successfully unloaded extension {cog}', color=color) await ctx.send(embed=embed)
async def on_command_error(self, ctx, error): if isinstance(error, commands.CommandNotFound): return elif isinstance(error, discord.Forbidden): embed = discord.Embed( title="Error", description= """I do not have enough permissions to execute this command. I require the following permissions:\nRead Messages, Send Messages, Embed Links, Add Reactions""", color=0xff0000) await ctx.send(embed=embed) return elif isinstance(error, commands.MissingRequiredArgument): embed = discord.Embed(title="Error", description="""Missing Required Argument.""", color=0xff0000) await ctx.send(embed=embed) return elif isinstance(error, commands.NotOwner): embed = discord.Embed( title="Error", description= """This command is either restricted, or is temporarily disabled for testing purposes.""", color=0xff0000) await ctx.send(embed=embed) return elif isinstance(error, commands.CommandOnCooldown): embed = discord.Embed( title="Cooldown", description= """That command is on cooldown, you may use it again once all data has been retrieved.""", color=0xff0000) await ctx.send(embed=embed) return else: error = getattr(error, "original", error) embed = discord.Embed( title="Error", description= """An unknown error occurred. This error has been reported. ```\n""" + str(error) + '\n```', color=0xff0000) await ctx.send(embed=embed) try: raise error except: tb = traceback.format_exc() con.log(error) with open('utils\\logs\\error.log', 'a') as logfile: logfile.write(tb) if logchannel is not None: channel = self.bot.get_channel(logchannel) if channel is not None: embed = discord.Embed( title=f"Exception in '{ctx.command}'", description=f"```\n{tb}\n```", color=0xff0000) try: await channel.send(embed=embed) except discord.Forbidden: raise ValueError( "The bot does not have permissions to send messages in the logchannel specified in config.ini." ) else: raise ValueError( "The logchannel specified in config.ini is not visible to the bot, or does not exist." ) return
from utils.utils import con import discord import os from discord.ext import commands from configparser import ConfigParser con.start() con.log("Starting bot...") intents = discord.Intents.default() parser = ConfigParser() parser.read('config.ini') TOKEN = parser.get('CONFIG', 'token') def get_prefix(bots, message): prefixes = ['h!', 'H!', 'h1', 'H1'] return commands.when_mentioned_or(*prefixes)(bots, message) bot = commands.Bot(command_prefix=get_prefix, case_insensitive=True, intents=intents) bot.remove_command('help') def load_extension(extension): ext = extension.replace('/', '.') try: bot.load_extension(ext) con.log(f"{ext} loaded.") except Exception as e: con.log(f"Couldn't load {ext}: {e}")
async def before_statuses(self): con.log('Waiting to run Statuses task...') await self.bot.wait_until_ready() con.log('Running Statuses...')