Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from Deprecated Library and Handle Discord Intents Update #93

Open
wants to merge 7 commits into
base: rewrite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cogs/Admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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))
10 changes: 5 additions & 5 deletions Cogs/Casino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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))
8 changes: 4 additions & 4 deletions Cogs/Colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
48 changes: 23 additions & 25 deletions Cogs/Economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))
4 changes: 2 additions & 2 deletions Cogs/Errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
8 changes: 4 additions & 4 deletions Cogs/Gelbooru.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
16 changes: 8 additions & 8 deletions Cogs/Info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -40,27 +40,27 @@ 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.
"""
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))
8 changes: 4 additions & 4 deletions Cogs/MAL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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))
22 changes: 17 additions & 5 deletions Cogs/Owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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))
Loading