From d28d840df4bb3572451d59c4901433768cae184b Mon Sep 17 00:00:00 2001 From: Aryan-401 Date: Mon, 10 Oct 2022 19:21:52 +0530 Subject: [PATCH 1/2] added custom error commands --- discord_main.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/discord_main.py b/discord_main.py index f4ece7b..d3bbef2 100644 --- a/discord_main.py +++ b/discord_main.py @@ -81,6 +81,31 @@ async def about(ctx): await ctx.send(embed=embed) + +@client.event +async def on_command_error(ctx, error): + if isinstance(error, commands.CommandNotFound): + return + elif isinstance(error, commands.MissingRequiredArgument): + if len("|".join(ctx.command.aliases)) > 0: + base = f'.[{ctx.command.name}|{"|".join(ctx.command.aliases)}]' + else: + base = f'.[{ctx.command.name}]' + error = f'{str(error)}\nCorrect syntax: ```{base} {ctx.command.signature}```' + else: + if str(error).startswith("Command"): + error = str(error)[29:] + else: + error = str(error) + embed = discord.Embed( + title="This isn't a 404 but...", + description=error, + colour=discord.Colour(0xE93316) + ) + embed.set_footer(text=f'For more information try running .help') + + await ctx.message.channel.send(embed=embed) + async def load(): for filename in os.listdir('./cogs'): if filename.endswith('.py'): From 1a0a7e3fe224c12753ae3649d72077ecd6f84824 Mon Sep 17 00:00:00 2001 From: Aryan-401 Date: Mon, 10 Oct 2022 19:26:33 +0530 Subject: [PATCH 2/2] minor aesthetic improvements --- discord_main.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/discord_main.py b/discord_main.py index d3bbef2..ed991e7 100644 --- a/discord_main.py +++ b/discord_main.py @@ -17,13 +17,14 @@ client.help_command = CustomHelpCommand() + @client.event async def on_guild_join(guild): general = find(lambda x: ('general' in x.name.lower()), guild.text_channels) if general and general.permissions_for(guild.me).send_messages: await general.send(embed=discord.Embed(title=f"Hello {guild.name}!", description="I am a bot that can help you to run fun commands. Type '.help' to get started", - color=discord.Color.blue())) + color=discord.Color.blurple())) @client.event @@ -37,6 +38,7 @@ async def invite(ctx): f"Server\n\nhttps://discord.com/api/oauth2/authorize?client_id=1028024794081394688&permissions" f"=172942961728&scope=bot") + @client.command(help='Get the bot\'s latency') async def ping(ctx): await ctx.channel.send(embed=discord.Embed(title="Pong!", description=f"Latency: {round(client.latency * 1000)}ms", @@ -77,7 +79,9 @@ async def about(ctx): f'at Thapar Institute.', colour=discord.Colour.blue()) embed.set_image( - url='https://ci6.googleusercontent.com/proxy/C8UxgGwLaoucxBN9rJCYvVOYnYFMjgd6Zy_xbQpuAE9dXa71YudYOwJN7MYZ4azkNQNc49u1d84eyt7Gdw2KQ8MgJJ9PJbHdbW9STiFzoNP-URezcXBKMfn0vd-1g7W5blB0WGFURZAmVbtJynA5sMV1xGcVA70=s0-d-e1-ft#https://res.cloudinary.com/dhoayd4fv/image/upload/v1664731326/MLSC/HacktoberFest_Header_3_xvtpyn.png') + url='https://ci6.googleusercontent.com/proxy/C8UxgGwLaoucxBN9rJCYvVOYnYFMjgd6Zy_xbQpuAE9dXa71YudYOwJN7MYZ4azk' + 'NQNc49u1d84eyt7Gdw2KQ8MgJJ9PJbHdbW9STiFzoNP-URezcXBKMfn0vd-1g7W5blB0WGFURZAmVbtJynA5sMV1xGcVA70=s0-d-e1-f' + 't#https://res.cloudinary.com/dhoayd4fv/image/upload/v1664731326/MLSC/HacktoberFest_Header_3_xvtpyn.png') await ctx.send(embed=embed) @@ -106,6 +110,7 @@ async def on_command_error(ctx, error): await ctx.message.channel.send(embed=embed) + async def load(): for filename in os.listdir('./cogs'): if filename.endswith('.py'):