diff --git a/Cogs/Admin.py b/Cogs/Admin.py index c577288..3537d50 100644 --- a/Cogs/Admin.py +++ b/Cogs/Admin.py @@ -14,7 +14,7 @@ class Admin(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command() @commands.has_permissions(administrator=True) @commands.bot_has_permissions(administrator=True) async def prefix(self, ctx, arg): @@ -28,7 +28,7 @@ async def prefix(self, ctx, arg): if(len(c.fetchall()) == 0): # The prefix has not seriously been set c.execute("INSERT INTO prefixes VALUES (?,?);", - str(ctx.channel.guild.id), arg) + [str(ctx.channel.guild.id), arg]) await ctx.send("Set prefix to `"+arg+"`!") else: c.execute( @@ -43,7 +43,7 @@ async def prefix(self, ctx, arg): conn.commit() conn.close() - @commands.command() + @commands.hybrid_command() @commands.has_permissions(ban_members=True) @commands.bot_has_permissions(ban_members=True) async def ban(self, ctx, arg): @@ -57,7 +57,7 @@ async def ban(self, ctx, arg): except Exception as e: raise APIError(str(e)) - @commands.command() + @commands.hybrid_command() @commands.has_permissions(kick_members=True) @commands.bot_has_permissions(kick_members=True) async def kick(self, ctx, arg): @@ -71,7 +71,7 @@ async def kick(self, ctx, arg): except Exception as e: raise APIError(str(e)) - @commands.command() + @commands.hybrid_command() @commands.has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def clear(self, ctx, arg): @@ -93,7 +93,7 @@ async def clear(self, ctx, arg): await ctx.message.channel.purge(limit=(int(arg)+1), bulk=True) await ctx.send("Deleted "+str(arg)+" messages!") - @commands.command() + @commands.hybrid_command() @commands.has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def mute(self, ctx, arg): @@ -107,7 +107,7 @@ async def mute(self, ctx, arg): else: await ctx.send("You must specify a user.") - @commands.command() + @commands.hybrid_command() @commands.has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def unmute(self, ctx, arg): @@ -121,5 +121,5 @@ async def unmute(self, ctx, arg): await ctx.send(ctx.message.channel.send("You must specify a user.")) -def setup(bot): - bot.add_cog(Admin(bot)) +async def setup(bot): + await bot.add_cog(Admin(bot)) diff --git a/Cogs/Casino.py b/Cogs/Casino.py index f7cd911..ef8d79c 100644 --- a/Cogs/Casino.py +++ b/Cogs/Casino.py @@ -13,7 +13,7 @@ class Casino(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command() async def roll(self, ctx, arg): """ Rolls the specified dice. @@ -40,7 +40,7 @@ async def roll(self, ctx, arg): name="Dice Roller", icon_url="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/game-die_1f3b2.png") await ctx.send(embed=embed) - @commands.command(name="8ball") + @commands.hybrid_command(name="8ball") async def eightball(self, ctx): """ Gets a message from the eight-ball. @@ -84,7 +84,7 @@ async def eightball(self, ctx): ) await ctx.send(embed=embed) - @commands.command() + @commands.hybrid_command() async def kekw(self, ctx): """ Posts a healthy bit of cringe. @@ -112,5 +112,5 @@ async def kekw(self, ctx): await ctx.send(embed=embed) -def setup(bot): - bot.add_cog(Casino(bot)) +async def setup(bot): + await bot.add_cog(Casino(bot)) diff --git a/Cogs/Colors.py b/Cogs/Colors.py index b7505b3..32fa525 100644 --- a/Cogs/Colors.py +++ b/Cogs/Colors.py @@ -12,7 +12,7 @@ class Colors(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command() @commands.has_permissions(manage_roles=True) @commands.bot_has_permissions(manage_roles=True) async def colors(self, ctx, status): @@ -33,7 +33,7 @@ async def colors(self, ctx, status): raise commands.BadArgument( "Invalid option. only enable/disable permitted.") - @commands.command() + @commands.hybrid_command() async def color(self, ctx, color): """ Set your color role. @@ -100,8 +100,8 @@ async def inv_color(self, ctx, userName, hex): await ctx.send(("{0.author.mention}, changed your color to " + hex + "!").format(ctx.message)) -def setup(bot): - bot.add_cog(Colors(bot)) +async def setup(bot): + await bot.add_cog(Colors(bot)) def setColorMode(status, serverID): diff --git a/Cogs/Economy.py b/Cogs/Economy.py index 4343205..55e8c70 100644 --- a/Cogs/Economy.py +++ b/Cogs/Economy.py @@ -12,47 +12,45 @@ class Economy(commands.Cog): def __init__(self, bot): self.bot: Bot = bot - @commands.command() + @commands.hybrid_command() async def score(self, ctx): """Gets the amount of money you have.""" if(len(ctx.message.mentions) == 0): user = ctx.message.author else: user = ctx.message.mentions[0] - await ctx.send("`" + str(user.name) + "`'s score is: " + str(getScore(user.id))) + await ctx.send(f"`{str(user.name)}`'s score is: {str(getScore(user.id))}") - @commands.command() - async def fight(self, ctx): + @commands.hybrid_command() + async def fight(self, ctx, *, opponent: discord.Member = None): """Fights a user and rewards points to the winner.""" - numPlayers = len(ctx.message.mentions) + # Opponent can only sadly be a single user with slash commands. + numPlayers = 1 if (opponent!=None) else len(ctx.message.mentions) vicNum = random.randint(0, numPlayers) rewardAmt = random.randint(1, 5) if(numPlayers < 1) or (ctx.message.author in ctx.message.mentions): - msg = '<@!' + str(ctx.message.author.id)+'>' + \ - ", you can't fight yourself! Choose a set of opponents." + msg = f"<@!{str(ctx.message.author.id)}>" + \ + f", you can't fight yourself! Choose a set of opponents." await ctx.send(msg) else: - victor = ctx.message.author if vicNum == numPlayers else ctx.message.mentions[vicNum] + victor = ctx.message.author if vicNum == numPlayers else (ctx.message.mentions[vicNum] if + opponent == None else opponent) await addPoints(str(ctx.message.guild.id), str(victor.id), rewardAmt) msg = '<@!'+str(victor.id)+'>' + " wins! " + str(rewardAmt) msg += " point." if rewardAmt == 1 else " points." - await ctx.send(msg) if numPlayers < 2: if not victor == ctx.message.author: await addPoints(str(ctx.message.guild.id), str(ctx.message.author.id), rewardAmt * -1) loser = str(ctx.message.author.id) else: - await addPoints(str(ctx.message.guild.id), str(ctx.message.mentions[0].id), rewardAmt * -1) - loser = str(ctx.message.mentions[0].id) - msg = '<@!' + loser + '>' + \ - ": For your loss, you lose " + str(rewardAmt) - if rewardAmt == 1: - msg += " point. Better luck next time." - else: - msg += " points. Better luck next time." + await addPoints(str(ctx.message.guild.id), str(ctx.message.mentions[0].id + if opponent == None else opponent.id), rewardAmt * -1) + loser = str(ctx.message.mentions[0].id if opponent == None else opponent.id) + msg += f"\n<@!{loser}>: For your loss, you lose {str(rewardAmt)}" + \ + f" {' point.' if rewardAmt == 1 else ' points.'} Better luck next time!" await ctx.send(msg) - @commands.command() + @commands.hybrid_command() async def leaderboard(self, ctx, arg1=None): """Gets the leaderboard.""" if arg1 is None: @@ -91,8 +89,8 @@ async def leaderboard(self, ctx, arg1=None): name="Leaderboard", icon_url="https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/120/microsoft/209/money-bag_1f4b0.png") await ctx.send(embed=embed) - @commands.command() - async def give(self, ctx: Context, _, amount: str = 0, *args): + @commands.hybrid_command() + async def give(self, ctx: Context, amount: int = 0, *, args): """ Give points to another player via mention """ # Make sure amount is a valid number try: @@ -132,7 +130,7 @@ async def give(self, ctx: Context, _, amount: str = 0, *args): # Final output message await ctx.send(f'Added {amount} points to <@!{mention.id}>\'s score courtesy of <@!{msg.author.id}>.') - @commands.command() + @commands.hybrid_command() async def shop(self, ctx): """displays shop and allows user to buy items""" # displaying initial shop menu with emoji reactions for user input @@ -193,8 +191,8 @@ def isHex(hexcode): await addItem(str(ctx.message.author.id), msg.content.strip().upper(), 1) await ctx.send('<@!' + str(ctx.message.author.id)+'>, your custom color ' + msg.content + ' has been added to your inventory. You now have ' + str(score-20) + ' points.') - @commands.command() - async def inv(self, ctx, *args): + @commands.hybrid_command() + async def inv(self, ctx, *, args): """displays a users inventory""" # displaying a mentioned users inventory if len(args) == 1 and len(ctx.message.mentions) == 1: @@ -369,5 +367,5 @@ async def display_inventory(self, ctx, userID, inventory): await ctx.send(embed=embed) -def setup(bot): - bot.add_cog(Economy(bot)) +async def setup(bot): + await bot.add_cog(Economy(bot)) diff --git a/Cogs/Errors.py b/Cogs/Errors.py index bd98558..9c490c2 100644 --- a/Cogs/Errors.py +++ b/Cogs/Errors.py @@ -58,5 +58,5 @@ async def generateErrorEmbed(msg): return discord.Embed(color=0xff0000, title="Error", description=msg) -def setup(bot): - bot.add_cog(Errors(bot)) +async def setup(bot): + await bot.add_cog(Errors(bot)) diff --git a/Cogs/Gelbooru.py b/Cogs/Gelbooru.py index b06943a..2864889 100644 --- a/Cogs/Gelbooru.py +++ b/Cogs/Gelbooru.py @@ -38,9 +38,9 @@ def __init__(self, bot): self.session = aiohttp.ClientSession() self.validSubCommands = ['id','latest','random','tags'] - @commands.command() + @commands.hybrid_command() @commands.is_nsfw() - async def gelbooru(self, ctx, *args): + async def gelbooru(self, ctx, *, args): if(len(args) == 0): raise InvalidSubcommand('Please enter a subcommand.') elif not str(args[0]).lower() in self.validSubCommands: @@ -125,5 +125,5 @@ def __init__(self, message="Gelbooru API error."): super().__init__(message) -def setup(bot): - bot.add_cog(booru(bot)) +async def setup(bot): + await bot.add_cog(booru(bot)) diff --git a/Cogs/Info.py b/Cogs/Info.py index 883faf4..927a301 100644 --- a/Cogs/Info.py +++ b/Cogs/Info.py @@ -11,7 +11,7 @@ class Info(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command() async def info(self, ctx): """ Sends the user information about the bot. @@ -20,7 +20,7 @@ async def info(self, ctx): ctx.prefix + "`. To get help use `"+ctx.prefix+"help`." await ctx.send(msg) - @commands.command() + @commands.hybrid_command() async def hello(self, ctx): """ Says hello to the user. @@ -29,7 +29,7 @@ async def hello(self, ctx): + "https://cdn.discordapp.com/attachments/402744318013603840/430592483282386974/image.gif").format(ctx.message) await ctx.send(msg) - @commands.command() + @commands.hybrid_command() async def codeformat(self, ctx): """ Explains how to format code in Discord. @@ -40,21 +40,21 @@ async def codeformat(self, ctx): + "Replace \"python\" with the language you are using to get some pretty syntax highlighting!") await ctx.send(msg) - @commands.command() + @commands.hybrid_command() async def donate(self, ctx): """ Returns the Patreon donation link. """ await ctx.send("Help my programmer out, become a patron today! https::www.patreon.com/LeoSaucedo") - @commands.command() + @commands.hybrid_command() async def vote(self, ctx): """ Returns the dbl vote link. """ await ctx.send("Vote for me to take over the world! https://discordbots.org/bot/430482288053059584/vote") - @commands.command() + @commands.hybrid_command() async def latency(self, ctx): """ Returns the latency of the bot. @@ -62,5 +62,5 @@ async def latency(self, ctx): await ctx.send("Latency: " + str(int(ctx.bot.latency * 1000)) + "ms") -def setup(bot): - bot.add_cog(Info(bot)) +async def setup(bot): + await bot.add_cog(Info(bot)) diff --git a/Cogs/MAL.py b/Cogs/MAL.py index 4b5394d..e453448 100644 --- a/Cogs/MAL.py +++ b/Cogs/MAL.py @@ -226,8 +226,8 @@ class MyAnimeList(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() - async def mal(self, ctx, *args): + @commands.hybrid_command() + async def mal(self, ctx, *, args): """Looks up an anime on MAL.""" if args[0].lower() == 'id': data = await fetchItem(session, ''.join(args[1:]).upper()) @@ -314,5 +314,5 @@ def __init__(self, message='Invalid ID.'): super().__init__(message) -def setup(bot): - bot.add_cog(MyAnimeList(bot)) +async def setup(bot): + await bot.add_cog(MyAnimeList(bot)) diff --git a/Cogs/Owner.py b/Cogs/Owner.py index b612002..5028a82 100644 --- a/Cogs/Owner.py +++ b/Cogs/Owner.py @@ -12,7 +12,7 @@ class Owner(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command(name="reload", hidden=True) + @commands.hybrid_command(name="reload", hidden=True, with_app_command=False) @commands.is_owner() async def _reload(self, ctx, arg): """Reloads a cog. @@ -27,7 +27,7 @@ async def _reload(self, ctx, arg): except Exception as e: raise e - @commands.command(hidden=True) + @commands.hybrid_command(hidden=True, with_app_command=False) @commands.is_owner() async def load(self, ctx, arg): """Adds a cog. @@ -42,7 +42,7 @@ async def load(self, ctx, arg): except Exception as e: raise e - @commands.command(hidden=True) + @commands.hybrid_command(hidden=True, with_app_command=False) @commands.is_owner() async def unload(self, ctx, arg): """Removes a cog. @@ -57,6 +57,18 @@ async def unload(self, ctx, arg): except Exception as e: raise e + @commands.hybrid_command(hidden=True, with_app_command=False) + @commands.is_owner() + async def sync(self, ctx): + """ + Globally syncs all bot commands with Discord. Should be run after adding or removing commands. + + Args: + ctx (discord.ext.Context): The message Context. + """ + response = await ctx.bot.tree.sync() # if wanting to sync with a specific guild, include guild=ctx.guild + return await ctx.send(f"Synced {len(response)} commands to Discord.") + -def setup(bot): - bot.add_cog(Owner(bot)) +async def setup(bot): + await bot.add_cog(Owner(bot)) diff --git a/Cogs/Roles.py b/Cogs/Roles.py index a540369..eb4bbb1 100644 --- a/Cogs/Roles.py +++ b/Cogs/Roles.py @@ -12,17 +12,17 @@ class Roles(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command() @commands.has_permissions(manage_roles=True) @commands.bot_has_permissions(manage_roles=True) - async def assign(self, ctx, status, roleName): + async def assign(self, ctx, status, *, args): """Enables or disables the given role for assignment.""" - role = discord.utils.get(ctx.guild.roles, name=(roleName)) + role = discord.utils.get(ctx.guild.roles, name=str(args)) if(status == "enable"): # Enable assignment if(role == None): # Role does not exist, create new role - role = await ctx.guild.create_role(name=str(roleName)) + role = await ctx.guild.create_role(name=str(args)) # Role already exists # Set the role as assignable setAssign(ctx.guild.id, role.id, True) @@ -43,7 +43,7 @@ async def assign(self, ctx, status, roleName): "Invalid option. Only enable/disable permitted.") return - @commands.command() + @commands.hybrid_command() async def iamlist(self, ctx): """Lists the assignable roles.""" assignList = "" @@ -72,11 +72,11 @@ async def iamlist(self, ctx): await ctx.send("{0.author.mention}, no assignable roles have been set." .format(ctx.message)) - @commands.command() - async def iam(self, ctx, roleName): + @commands.hybrid_command() + async def iam(self, ctx, *, args): """Assigns you to the specified role.""" # Check to see if role exists. - role = discord.utils.get(ctx.guild.roles, name=roleName) + role = discord.utils.get(ctx.guild.roles, name=str(args)) if(role == None): # Role does not exist await ctx.send("{0.author.mention}, that role does not exist!" @@ -95,11 +95,11 @@ async def iam(self, ctx, roleName): await ctx.send("{0.author.mention}, that role is already assigned to you!".format( ctx.message)) - @commands.command() - async def iamnot(self, ctx, roleName): + @commands.hybrid_command() + async def iamnot(self, ctx, *, args): """Unassigns you from the specified role.""" # Check to see if role exists. - role = discord.utils.get(ctx.guild.roles, name=roleName) + role = discord.utils.get(ctx.guild.roles, name=str(args)) if(role == None): # Role does not exist await ctx.send("{0.author.mention}, that role does not exist!" @@ -175,5 +175,5 @@ def getAssignList(serverId): return assignList -def setup(bot): - bot.add_cog(Roles(bot)) +async def setup(bot): + await bot.add_cog(Roles(bot)) diff --git a/Cogs/Trivia.py b/Cogs/Trivia.py index 6d7ccde..89f6eea 100644 --- a/Cogs/Trivia.py +++ b/Cogs/Trivia.py @@ -11,7 +11,7 @@ def __init__(self, bot): self.bot = bot self.currentQuestions = {} - @commands.command() + @commands.hybrid_command() async def ask(self, ctx): """Ask a trivia question.""" conn = sqlite3.connect("db/database.db") @@ -25,7 +25,7 @@ async def ask(self, ctx): } await ctx.send(question[0]) - @commands.command(pass_context=True, aliases=['a']) + @commands.hybrid_command(pass_context=True, aliases=['a']) async def answer(self, ctx, *, answer): """Answer a trivia question.""" if ctx.guild.id not in self.currentQuestions: @@ -39,7 +39,7 @@ async def answer(self, ctx, *, answer): else: await ctx.send("Incorrect!") - @commands.command() + @commands.hybrid_command() async def reveal(self, ctx): """Reveal the answer to a trivia question.""" if ctx.guild.id not in self.currentQuestions: @@ -48,7 +48,7 @@ async def reveal(self, ctx): await ctx.send(self.currentQuestions[ctx.guild.id]["answer"]) del self.currentQuestions[ctx.guild.id] - @commands.command() + @commands.hybrid_command() async def hint(self, ctx): """Give a hint to the answer to a trivia question.""" if ctx.guild.id not in self.currentQuestions: @@ -91,5 +91,5 @@ def format(attempt): return formatted -def setup(bot): - bot.add_cog(Trivia(bot)) +async def setup(bot): + await bot.add_cog(Trivia(bot)) diff --git a/Cogs/Utils.py b/Cogs/Utils.py index 553e7bf..bc6ea2a 100644 --- a/Cogs/Utils.py +++ b/Cogs/Utils.py @@ -12,7 +12,7 @@ class Utils(commands.Cog): def __init__(self, bot): self.bot = bot - @commands.command() + @commands.hybrid_command() async def sayd(self, ctx, *, arg): """Allows the user to send an anonymous message. """ @@ -22,7 +22,7 @@ async def sayd(self, ctx, *, arg): await ctx.send(arg) await ctx.message.delete() - @commands.command() + @commands.hybrid_command() async def quickvote(self, ctx, *, arg): """Generates a poll for the specified argument. @@ -33,18 +33,18 @@ async def quickvote(self, ctx, *, arg): # Makes a new vote, and adds a yes and a no reaction option. voteEmbed = discord.Embed(color=0x0080c0, description=arg) voteEmbed.set_author( - name="New Vote by " + ctx.author.name + "!", icon_url=ctx.author.avatar_url) + name="New Vote by " + ctx.author.name + "!", icon_url=ctx.author.avatar.url) voteMsg = await ctx.send(embed=voteEmbed) await voteMsg.add_reaction("👍") await voteMsg.add_reaction("👎") await ctx.message.delete() - @commands.command() + @commands.hybrid_command() async def rate(self, ctx, *, arg): """Rates the argument out of 10. """ await ctx.send("I rate `"+arg+"` a "+random.randint(0, 10)+"/10!") -def setup(bot): - bot.add_cog(Utils(bot)) +async def setup(bot): + await bot.add_cog(Utils(bot)) diff --git a/Cogs/Wolfram.py b/Cogs/Wolfram.py index dbaa339..2dc5884 100644 --- a/Cogs/Wolfram.py +++ b/Cogs/Wolfram.py @@ -17,7 +17,7 @@ def __init__(self, bot): self.bot = bot self.key = json.load(open("json/config.json", "r"))["wolframapi"] - @commands.command() + @commands.hybrid_command() async def wolfimg(self, ctx, *, arg): """Sends an image result from Wolfram. @@ -45,7 +45,7 @@ async def wolfimg(self, ctx, *, arg): embed.set_image(url="attachment://wolfram.jpg") await ctx.send(file=image, embed=embed) - @commands.command() + @commands.hybrid_command() async def wolfram(self, ctx, *, arg): """Sends a text response from Wolfram. @@ -72,5 +72,5 @@ def __init__(self, message="Wolfram API Error."): super().__init__(message) -def setup(bot): - bot.add_cog(Wolfram(bot)) +async def setup(bot): + await bot.add_cog(Wolfram(bot)) diff --git a/Cogs/Xkcd.py b/Cogs/Xkcd.py index 8ed7fce..39b3bc3 100644 --- a/Cogs/Xkcd.py +++ b/Cogs/Xkcd.py @@ -16,20 +16,20 @@ def __init__(self, bot): self.formattable_request_url = 'http://xkcd.com/{}/info.0.json' self.latest_request_url = 'http://xkcd.com/info.0.json' - @commands.command() - async def xkcd(self, ctx: Context, optional: Optional[str], *args): + @commands.hybrid_command() + async def xkcd(self, ctx: Context, args: Optional[str] = None): embed: Optional[Embed] = None - if optional is None or optional == 'random': + if args is None or args == 'random': embed = Xkcd._make_embed(await self.get_specific(randint(0, 100))) - elif optional == 'latest': + elif args == 'latest': embed = Xkcd._make_embed(await self.get_latest()) - elif Xkcd._try_convert(optional) is not None: - embed = Xkcd._make_embed(await self.get_specific(Xkcd._try_convert(optional))) + elif Xkcd._try_convert(args) is not None: + embed = Xkcd._make_embed(await self.get_specific(Xkcd._try_convert(args))) - if embed is not None and embed is not Embed.Empty: + if embed is not None and len(embed) > 0: return await ctx.send(embed=embed) - elif embed is Embed.Empty: + elif embed is None: # If embed is Embed.Empty that means json response was not value / invalid input return await ctx.send('Sorry, I was unable to retrieve that comic for your. It may not exist. . .') @@ -89,5 +89,5 @@ def _try_convert(n: str) -> Optional[int]: return None -def setup(bot): - bot.add_cog(Xkcd(bot)) +async def setup(bot): + await bot.add_cog(Xkcd(bot)) diff --git a/requirements.txt b/requirements.txt index 8694948..59f4fba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -discord.py>=1.2.3 +discord.py>=2.1.0 asyncio googletrans bs4 -dblpy==0.2 +topggpy==2.0.0a pushbullet.py lxml aiofiles \ No newline at end of file diff --git a/robot.py b/robot.py index f313294..75b8d86 100644 --- a/robot.py +++ b/robot.py @@ -7,8 +7,9 @@ from discord.ext import commands import json import sqlite3 -import dbl +import topgg import logging +import asyncio # The different Cogs supported by Rikka. cogs = [ @@ -39,16 +40,19 @@ def get_prefix(bot, message): Returns: string: The server's prefix, `;` if no set prefix. """ + log_info("Received: " + message.content) if not message.guild: return ';' conn = sqlite3.connect("db/database.db") c = conn.cursor() c.execute("SELECT prefix FROM prefixes WHERE server=?", - (str(message.guild.id),)) - prefix = c.fetchall() + [message.guild.id]) + prefix = c.fetchone() if(len(prefix) == 0): + log_info(f"No prefix found for server {message.guild.id}") return ';' else: + log_info(f"Prefix for server {message.guild.id} is {prefix[0]}") return prefix[0] @@ -57,8 +61,9 @@ def log_info(message): print(message) -bot = commands.AutoShardedBot(command_prefix=get_prefix) -botlist = dbl.Client(bot, json.load(open("json/config.json"))["bltoken"]) +intents = discord.Intents.all() +bot = commands.AutoShardedBot(command_prefix=get_prefix, intents=intents) +botlist = topgg.DBLClient(json.load(open("json/config.json"))["bltoken"]).set_data(bot) logging.basicConfig( filename="bot.log", filemode='w', @@ -76,12 +81,12 @@ async def on_ready(): log_info("Connected to: " + str(len(bot.guilds)) + " guilds.") log_info("Connected to: " + str(len(bot.users)) + " users.") - # DBL authentication + # topgg authentication try: await botlist.post_guild_count() - log_info("Published server count to dbl.") + log_info("Published server count to topgg.") except Exception as e: - log_info("Failed to post server count to dbl: " + str(e)) + log_info("Failed to post server count to topgg: " + str(e)) game = discord.Game(name="on " + str(len(bot.guilds))+" guilds!") await bot.change_presence(activity=game) @@ -104,12 +109,16 @@ async def on_guild_remove(guild): game = discord.Game(name="on " + str(len(bot.guilds))+" guilds!") await bot.change_presence(activity=game) - -if __name__ == "__main__": - # Add all cogs. +async def main(): + """Loads the cogs and runs the bot. + """ for cog in cogs: - bot.load_extension(cog) + try: + await bot.load_extension(cog) + log_info("Loaded " + cog) + except Exception as e: + log_info("Failed to load " + cog + ": " + str(e)) + await bot.start(json.load(open("json/config.json"))["token"]) - while True: - # Load bot token and run bot. - bot.run(json.load(open("json/config.json", "r"))["token"]) +if __name__ == "__main__": + asyncio.run(main())