From f92f70d017baba0f4f02a70b34b6e66e9dcef16a Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Wed, 10 Feb 2021 19:29:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20-=20Quick=20fix=20for=20DMs=20th?= =?UTF-8?q?at=20was=20generating=20errors=20because=20the=20bot=20couldn't?= =?UTF-8?q?=20delete=20messages=20;=20errors=20are=20now=20handled.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index de9ba8f..f86e8eb 100644 --- a/main.py +++ b/main.py @@ -72,6 +72,13 @@ def check_user(name): return True +async def del_message(ctx): + try: + await ctx.message.delete() + except discord.errors.Forbidden: + pass + + @bot.event async def on_ready(): default_activity = discord.Activity(type=discord.ActivityType.listening, name="$help") @@ -81,7 +88,7 @@ async def on_ready(): @bot.command() async def chat_set(ctx, arg1): - await ctx.message.delete() + await del_message(ctx) what_channel = ctx.channel if what_channel in list(chats): await ctx.send("```A chat is already active, you have to stop it before with the cmd $chat_stop !```") @@ -99,7 +106,7 @@ async def chat_set(ctx, arg1): @bot.command() async def chat_stop(ctx): - await ctx.message.delete() + await del_message(ctx) chan = ctx.channel if chan in list(chats): chats[chan].twitch.stop() @@ -113,7 +120,7 @@ async def chat_stop(ctx): @bot.command() async def rank(ctx, arg, argf=None): - await ctx.message.delete() + await del_message(ctx) if argf is None: try: player = WATCHER.summoner.by_name(REGION, arg) @@ -129,7 +136,7 @@ async def rank(ctx, arg, argf=None): embed.description = ranks await ctx.send(embed=embed) except ApiError: - await ctx.send("The nickname is unknow.") + await ctx.send("The nickname is unknown.") else: await ctx.send("If you are trying to use a nickname with spaces, please surround it with quotes.") @@ -140,7 +147,7 @@ async def issou(ctx, arg1: discord.User = None): user = arg1 else: user = ctx.message.author - await ctx.message.delete() + await del_message(ctx) try: voice_channel = user.voice.channel except AttributeError: