Added more try/catch commands for errors

Fixed some of the commands
testing
sgoudham 5 years ago
parent 913b5f98e2
commit 2f482b098e

@ -98,33 +98,14 @@ class Fun(commands.Cog):
@cooldown(1, 0.5, BucketType.channel) @cooldown(1, 0.5, BucketType.channel)
async def kissing(self, ctx, target: discord.Member): async def kissing(self, ctx, target: discord.Member):
if commands.has_any_role('Hamothy'): channels = ["bot-commands"]
with open('kissing.txt') as file:
kissing_array = file.readlines()
# set member as the author
member = ctx.message.author
userAvatar = member.avatar_url
embed = discord.Embed(
title=f"<:blushlook1:677310734123663363> <:blushlook2:679524467248201769> | **{member.display_name}** kissed **{target.display_name}**",
colour=discord.Colour(int(random.choice(colours))))
embed.set_image(url=random.choice(kissing_array))
embed.set_footer(text=f"Requested by {ctx.message.author}", icon_url='{}'.format(userAvatar))
await ctx.send(embed=embed)
else:
channels = ["bot commands"]
try:
if str(ctx.channel) in channels: if str(ctx.channel) in channels:
with open('kissing.txt') as file: with open('kissing.txt') as file:
kissing_array = file.readlines() kissing_array = file.readlines()
if str(ctx.channel) in channels:
# set member as the author # set member as the author
member = ctx.message.author member = ctx.message.author
userAvatar = member.avatar_url userAvatar = member.avatar_url
@ -137,8 +118,6 @@ class Fun(commands.Cog):
await ctx.send(embed=embed) await ctx.send(embed=embed)
# await self.bot.say("hugs {}".format(ctx.message.author.mention()))
else: else:
message = await ctx.send(error_function()) message = await ctx.send(error_function())
@ -147,6 +126,8 @@ class Fun(commands.Cog):
await asyncio.sleep(2.5) await asyncio.sleep(2.5)
# Delete the message # Delete the message
await message.delete() await message.delete()
except FileNotFoundError as e:
print(e)
# Bot ~8Ball command # Bot ~8Ball command
@commands.command(aliases=['8ball', '8Ball']) @commands.command(aliases=['8ball', '8Ball'])
@ -155,19 +136,24 @@ class Fun(commands.Cog):
channels = ["bot-commands"] channels = ["bot-commands"]
try:
if str(ctx.channel) in channels:
with open('eightball.txt') as file: with open('eightball.txt') as file:
_8ball_array = file.readlines() _8ball_array = file.readlines()
if str(ctx.channel) in channels:
await ctx.send(f'Question: {question}\nAnswer: {random.choice(_8ball_array)}') await ctx.send(f'Question: {question}\nAnswer: {random.choice(_8ball_array)}')
else: else:
message = await ctx.send(error_function()) message = await ctx.send(error_function())
# Let the user read the message for 2.5 seconds # Let the user read the message for 2.5 seconds
await asyncio.sleep(2.5) await asyncio.sleep(2.5)
# Delete the message # Delete the message
await message.delete() await message.delete()
except FileNotFoundError as e:
print(e)
@commands.Cog.listener() @commands.Cog.listener()
async def on_command_error(self, ctx, target: discord.member): async def on_command_error(self, ctx, target: discord.member):

Loading…
Cancel
Save