async def upload_json_to_discord( self ): # I fisrt used to upload the whole thing as a file, but that's actually the worst thing to o because that can get this rate limited real quick, so i'm make it send it in a message instead channel_to_upload_to = self.client.get_channel( json.loads( read_file("config.json"))["json_file_upload_channel_id"]) console_log( "Attempting to upload, or send the json file data to TC:{}({})". format(channel_to_upload_to.name, channel_to_upload_to.id), "yellow") try: # await channel_to_upload_to.send(file=discord.File("id-list.json")) json_to_send = "" for i in read_file("id-list.json"): json_to_send = json_to_send + i if len( json_to_send ) > 1900: # Send message limit is 2000, keeping it to 1900 just to be on the safe side await channel_to_upload_to.send( f"```json\n{json_to_send}```") json_to_send = "" await channel_to_upload_to.send(f"```json\n{json_to_send}```") console_log("JSON file data sent", "green") except Exception as e: console_log(f"Upload JSON data failed: {e}", "red")
def __init__(self, client): self.client = client self.save_data_as_json.start() self.upload_json_to_discord.start() try: read_file('id-list.json') except: f = open('id-list.json', 'w') f.write(json.dumps(initial_json)) f.close()
async def botinfo(ctx): await ctx.send(embed=discord.Embed( title="Bot info", description=json.loads(read_file("config.json"))["bot_info"].replace( "$p$", client.prefix()), color=discord.Color.gold() ).set_author( name=f'{ctx.author}', icon_url= f'https://cdn.discordapp.com/avatars/{ctx.author.id}/{ctx.author.avatar}.png' ))
async def debug_upload_json_to_discord(self, ctx): channel_to_upload_to = self.client.get_channel(json.loads(read_file("config.json"))["json_file_upload_channel_id"]) console_log("Attempting to upload the json file to TC.{}({}) (requested through debug command)".format(channel_to_upload_to.name, channel_to_upload_to.id), "yellow") await ctx.send("Attempting to upload the json file to TC.{}({}) (requested through debug command)".format(channel_to_upload_to.name, channel_to_upload_to.id)) try: await channel_to_upload_to.send(file=discord.File("id-list.json")) console_log("JSON file upload success", "green") await ctx.send("JSON file upload success") except Exception as e: console_log(f"Upload JSON failed: {e}", "red") await ctx.send(f"Upload JSON failed: {e}")
async def suggest(ctx, *, to_suggest): await ctx.send(embed=discord.Embed( title="Suggestion submitted", description= f'The suggestion has been submitted to my creator, which says:```{to_suggest}```', color=discord.Color.green()).set_footer( text="Thank you for reporting and making me a better bot")) await client.get_channel( json.loads(read_file("config.json"))["suggestions_channel_id"] ).send(embed=discord.Embed( title=f"Suggestion", description=f"```{to_suggest}```", color=discord.Color.green() ).set_author( name=f'{ctx.author}', icon_url= f'https://cdn.discordapp.com/avatars/{ctx.author.id}/{ctx.author.avatar}.png' ))
def boot_bot( blacklisted_extensions: tuple ) -> None: # i am not using the on_ready event because then the on_ready event in cogs won't work, and putting it all in a function so its looking clean # unecessary decoration (i like it please don't attack me) if sys.platform == "win32" or sys.platform == "win64": os.system("cls") else: os.system("clear") cprint(read_file("startup_ascii.txt").format(client.version), "yellow") # getting list of all paths to extensions filelist = [] for root, dirs, files in os.walk("data/"): for file in files: filelist.append(os.path.join(root, file)) # And then loading them lines = 0 #this is just a small thing i did for counting the lines of code written for file in filelist: if file.endswith('.py'): file = file.replace('/', '.').replace('\\', '.')[:-3] try: if file not in blacklisted_extensions: client.load_extension(f"{file}") console_log(f"Loaded extension: {file}", "yellow") else: console_log(f"Blacklisted extension not loaded: {file}", "red") except NoEntryPointError: console_log( f"{file} has no entry point, assuming that its not an extension.", "blue") except Exception as e: console_log( f"Failed to load the extension: {file}, reason: {sys.exc_info()[0]}, {e}`", "white", "on_red")
client.load_extension(f"{file}") console_log(f"Loaded extension: {file}", "yellow") else: console_log(f"Blacklisted extension not loaded: {file}", "red") except NoEntryPointError: console_log( f"{file} has no entry point, assuming that its not an extension.", "blue") except Exception as e: console_log( f"Failed to load the extension: {file}, reason: {sys.exc_info()[0]}, {e}`", "white", "on_red") boot_bot(blacklisted_extensions=json.loads(read_file("config.json")) ["blacklisted_extensions"]) @client.event async def on_ready(): await asyncio.sleep( 5 ) # Gotta wait for the extensions to do their thing first, (for e.g. id_list needs to be defined) # Making sure every server has a default prefix to avoid future errors try: client.id_list['prefixes'] except KeyError: client.id_list['prefixes'] = dict() console_log("Serving in the following guilds:") for guild in client.guilds:
def __init__(self, client): self.client = client self.emojis = json.loads(read_file('id-list.json'))['emojis']
import discord