Skip to content

Commit

Permalink
Shard the bot!
Browse files Browse the repository at this point in the history
I never thought i would co-own a bot in 1K servers 🥲
  • Loading branch information
Soapy7261 authored Jun 22, 2023
2 parents 3379a7d + 09445e4 commit 5d5c67f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cogs/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ async def info(self, ctx: bridge.BridgeContext):
**Users:** {sum(x.member_count for x in self.bot.guilds)}
**API Latency:** {round(self.bot.latency * 1000)}ms
**Protocol Latency:** {latency}ms
**Shard count:** {self.bot.shard_count}
**Shard:** {ctx.guild.shard_id + 1}
[[Invite]](https://discord.com/api/oauth2/authorize?client_id=889197952994791434&permissions=274878286912&scope=bot%20applications.commands) [[Support]](https://discord.gg/Ukr89GrMBk) [[Github]](https://github.com/BlackFurORG/pingernos) [[Privacy Policy]](https://gist.github.com/MiataBoy/20fda9024f277ea5eb2421adbebc2f23) [[Terms of Service]](https://gist.github.com/MiataBoy/81e96023a2aa055a038edab02e7e7792)
"""
Expand Down
16 changes: 11 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from discord import Intents, Status, Activity, ActivityType
from discord.ext.bridge import Bot
from discord.ext.bridge import AutoShardedBot
from utils import Utils

data = Utils.get_data()
intents = Intents(guilds=True, guild_messages=True)
# intents.message_content = True #Uncomment this if you use prefixed command that are not mentions
bot = Bot(intents=intents, command_prefix=data['Prefix'], status=Status.dnd,
activity=Activity(type=ActivityType.watching, name="you (prefix: @mention)"))
bot = AutoShardedBot(intents=intents, command_prefix=data['Prefix'], status=Status.dnd,
activity=Activity(type=ActivityType.watching, name="Starting..."))
bot.load_extensions("cogs") # Loads all cogs in the cogs folder
bot.help_command = Utils.HelpCmd() # Disables the default help command
BOOTED = False
Expand All @@ -20,15 +20,21 @@ async def on_connect():
database.execute("CREATE TABLE IF NOT EXISTS blacklist (guild_id VARCHAR(21) PRIMARY KEY, reason TEXT NOT NULL)")
database.close()

@bot.listen()
async def on_reconnect():
print('Reconnected to Discord!')

@bot.listen()
async def on_ready():
global BOOTED
global BOOTED #I'm sorry, but there's no other way to do this without classes which I want only in the cogs
if BOOTED:
print("Reconnect(?)")
if not BOOTED:
# await bot.sync_commands() #You might need to uncomment this if the slash commands aren't appearing
print(f'Logged in as {bot.user}')
print(f'Logged in as {bot.user} with {bot.shard_count+1} shards!')
print('------')
for shard in bot.shards:
await bot.change_presence(status=Status.dnd, activity=Activity(type=ActivityType.watching, name=f"you (prefix: @mention) | Shard: {shard+1}"), shard_id=shard)
BOOTED = True

bot.run(data['Token'])

0 comments on commit 5d5c67f

Please sign in to comment.