GoldyBot.bot
1import asyncio 2import nextcord 3from nextcord.ext import commands, tasks 4import os 5import time 6from platform import python_version 7 8import GoldyBot 9 10MODULE_NAME = "GOLDY CORE" 11 12def start(): 13 """Start the nextcord bot.""" 14 15 asyncio.set_event_loop(GoldyBot.async_loop) 16 17 TOKEN = GoldyBot.token.get() 18 DATABASE_TOKEN = GoldyBot.token.get_database() 19 intents = nextcord.Intents() 20 21 # Discord Bot 22 client = commands.Bot(command_prefix = GoldyBot.utility.nextcordpy.prefix.get_prefix, 23 case_insensitive=True, intents=intents.all(), help_command=None) 24 25 # Caching client object. 26 GoldyBot.cache.main_cache_dict["client"] = client 27 28 # Initializing Stuff 29 #---------------------- 30 GoldyBot.database.Database(DATABASE_TOKEN) # Initializing goldy bot database connection. 31 32 @client.event 33 async def on_ready(): 34 # Goldy Setup. 35 await GoldyBot.Goldy().setup(client) 36 37 await GoldyBot.utility.presence.change(f"{GoldyBot.info.name}", status=GoldyBot.nextcord.Status.online) 38 39 GoldyBot.log("info_2", f"[{MODULE_NAME}] [BOT READY]") 40 41 # Initializing Loops 42 #------------------------- 43 @tasks.loop(seconds=1) # Rate Limited Warning. 44 async def rate_limit_warning(): 45 if client.is_ws_ratelimited() == True: 46 GoldyBot.logging.log("warn", "We're being rate limited!") 47 48 rate_limit_warning.start() 49 50 @tasks.loop(seconds=1) # Stop Bot Loop 51 async def stop_bot(): 52 if GoldyBot.cache.main_cache_dict["bot_stop"]: 53 await client.close() 54 55 stop_bot.start() 56 57 # Goldy Setup. 58 #--------------- 59 GoldyBot.async_loop.create_task(GoldyBot.Goldy().setup(client)) 60 61 # Core commands 62 #---------------- 63 @GoldyBot.command(slash_cmd_only=True, required_roles=["bot_dev", "bot_admin"]) 64 async def goldy(ctx): 65 command_msg = GoldyBot.utility.msgs.goldy 66 system = GoldyBot.system.System() 67 hearts = GoldyBot.Hearts 68 69 version = GoldyBot.info.bot_version 70 nextcord_version = nextcord.__version__ 71 python_ver = python_version() 72 platform = system.os 73 74 dev_goldy = GoldyBot.Member(ctx, member_id=332592361307897856) # Hard coded my discord id LMAO. 75 dev_goldy_mention = GoldyBot.utility.commands.mention(dev_goldy) 76 77 embed = GoldyBot.utility.goldy.embed.Embed(title=command_msg.Embed.title) 78 embed.color = GoldyBot.utility.goldy.colours.AKI_BLUE 79 embed.set_thumbnail(url=GoldyBot.utility.goldy.get_pfp()) 80 81 embed.description = command_msg.Embed.des.format(version, nextcord_version, python_ver, round(client.latency * 1000), 82 platform, f"{system.cpu:.1f}", system.ram, system.disk, hearts.YELLOW, dev_goldy_mention) 83 84 message = await GoldyBot.utility.commands.send(ctx, embed=embed) 85 86 t_end = time.time() + 15 87 while time.time() < t_end: 88 heart = hearts.random() 89 embed.description = command_msg.Embed.des.format(version, nextcord_version, python_ver, round(client.latency * 1000), platform, f"{system.cpu:.1f}", system.ram, system.disk, heart, dev_goldy_mention) 90 await message.edit(embed=embed) 91 92 await asyncio.sleep(0.5) 93 94 95 96 try: 97 # Load internal modules. 98 #---------------------------- 99 for module in os.listdir(GoldyBot.paths.INTERNAL_COGS_V4): 100 if not module in ["__init__.py", "__pycache__"]: 101 GoldyBot.modules.Module(module_file_name=module).load() 102 103 # Load external modules. 104 #---------------------------- 105 for module in os.listdir(GoldyBot.paths.MODULES): 106 if not module in ["__pycache__", ".git"]: 107 GoldyBot.modules.Module(module_file_name=module).load() 108 109 except GoldyBot.errors.ModuleFailedToLoad: 110 # I just don't want it to stop the whole bot so I'm passing this exception. 111 pass 112 113 GoldyBot.ext.events.Events().register_all_nextcord_events() # Register events. 114 115 # Run Bot 116 #---------- 117 try: 118 GoldyBot.async_loop.run_until_complete(client.start(TOKEN)) 119 except Exception as e: # Error Handling 120 GoldyBot.logging.log("error", e); GoldyBot.Goldy().stop(e)
def
start():
13def start(): 14 """Start the nextcord bot.""" 15 16 asyncio.set_event_loop(GoldyBot.async_loop) 17 18 TOKEN = GoldyBot.token.get() 19 DATABASE_TOKEN = GoldyBot.token.get_database() 20 intents = nextcord.Intents() 21 22 # Discord Bot 23 client = commands.Bot(command_prefix = GoldyBot.utility.nextcordpy.prefix.get_prefix, 24 case_insensitive=True, intents=intents.all(), help_command=None) 25 26 # Caching client object. 27 GoldyBot.cache.main_cache_dict["client"] = client 28 29 # Initializing Stuff 30 #---------------------- 31 GoldyBot.database.Database(DATABASE_TOKEN) # Initializing goldy bot database connection. 32 33 @client.event 34 async def on_ready(): 35 # Goldy Setup. 36 await GoldyBot.Goldy().setup(client) 37 38 await GoldyBot.utility.presence.change(f"{GoldyBot.info.name}", status=GoldyBot.nextcord.Status.online) 39 40 GoldyBot.log("info_2", f"[{MODULE_NAME}] [BOT READY]") 41 42 # Initializing Loops 43 #------------------------- 44 @tasks.loop(seconds=1) # Rate Limited Warning. 45 async def rate_limit_warning(): 46 if client.is_ws_ratelimited() == True: 47 GoldyBot.logging.log("warn", "We're being rate limited!") 48 49 rate_limit_warning.start() 50 51 @tasks.loop(seconds=1) # Stop Bot Loop 52 async def stop_bot(): 53 if GoldyBot.cache.main_cache_dict["bot_stop"]: 54 await client.close() 55 56 stop_bot.start() 57 58 # Goldy Setup. 59 #--------------- 60 GoldyBot.async_loop.create_task(GoldyBot.Goldy().setup(client)) 61 62 # Core commands 63 #---------------- 64 @GoldyBot.command(slash_cmd_only=True, required_roles=["bot_dev", "bot_admin"]) 65 async def goldy(ctx): 66 command_msg = GoldyBot.utility.msgs.goldy 67 system = GoldyBot.system.System() 68 hearts = GoldyBot.Hearts 69 70 version = GoldyBot.info.bot_version 71 nextcord_version = nextcord.__version__ 72 python_ver = python_version() 73 platform = system.os 74 75 dev_goldy = GoldyBot.Member(ctx, member_id=332592361307897856) # Hard coded my discord id LMAO. 76 dev_goldy_mention = GoldyBot.utility.commands.mention(dev_goldy) 77 78 embed = GoldyBot.utility.goldy.embed.Embed(title=command_msg.Embed.title) 79 embed.color = GoldyBot.utility.goldy.colours.AKI_BLUE 80 embed.set_thumbnail(url=GoldyBot.utility.goldy.get_pfp()) 81 82 embed.description = command_msg.Embed.des.format(version, nextcord_version, python_ver, round(client.latency * 1000), 83 platform, f"{system.cpu:.1f}", system.ram, system.disk, hearts.YELLOW, dev_goldy_mention) 84 85 message = await GoldyBot.utility.commands.send(ctx, embed=embed) 86 87 t_end = time.time() + 15 88 while time.time() < t_end: 89 heart = hearts.random() 90 embed.description = command_msg.Embed.des.format(version, nextcord_version, python_ver, round(client.latency * 1000), platform, f"{system.cpu:.1f}", system.ram, system.disk, heart, dev_goldy_mention) 91 await message.edit(embed=embed) 92 93 await asyncio.sleep(0.5) 94 95 96 97 try: 98 # Load internal modules. 99 #---------------------------- 100 for module in os.listdir(GoldyBot.paths.INTERNAL_COGS_V4): 101 if not module in ["__init__.py", "__pycache__"]: 102 GoldyBot.modules.Module(module_file_name=module).load() 103 104 # Load external modules. 105 #---------------------------- 106 for module in os.listdir(GoldyBot.paths.MODULES): 107 if not module in ["__pycache__", ".git"]: 108 GoldyBot.modules.Module(module_file_name=module).load() 109 110 except GoldyBot.errors.ModuleFailedToLoad: 111 # I just don't want it to stop the whole bot so I'm passing this exception. 112 pass 113 114 GoldyBot.ext.events.Events().register_all_nextcord_events() # Register events. 115 116 # Run Bot 117 #---------- 118 try: 119 GoldyBot.async_loop.run_until_complete(client.start(TOKEN)) 120 except Exception as e: # Error Handling 121 GoldyBot.logging.log("error", e); GoldyBot.Goldy().stop(e)
Start the nextcord bot.