🩹 - Quick fix for DMs that was generating errors because the bot couldn't delete messages ; errors are now handled.

This commit is contained in:
Florian SYLVAIN
2021-02-10 19:29:39 +01:00
parent 6c29fa04dc
commit f92f70d017
+12 -5
View File
@@ -72,6 +72,13 @@ def check_user(name):
return True return True
async def del_message(ctx):
try:
await ctx.message.delete()
except discord.errors.Forbidden:
pass
@bot.event @bot.event
async def on_ready(): async def on_ready():
default_activity = discord.Activity(type=discord.ActivityType.listening, name="$help") default_activity = discord.Activity(type=discord.ActivityType.listening, name="$help")
@@ -81,7 +88,7 @@ async def on_ready():
@bot.command() @bot.command()
async def chat_set(ctx, arg1): async def chat_set(ctx, arg1):
await ctx.message.delete() await del_message(ctx)
what_channel = ctx.channel what_channel = ctx.channel
if what_channel in list(chats): 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 !```") 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() @bot.command()
async def chat_stop(ctx): async def chat_stop(ctx):
await ctx.message.delete() await del_message(ctx)
chan = ctx.channel chan = ctx.channel
if chan in list(chats): if chan in list(chats):
chats[chan].twitch.stop() chats[chan].twitch.stop()
@@ -113,7 +120,7 @@ async def chat_stop(ctx):
@bot.command() @bot.command()
async def rank(ctx, arg, argf=None): async def rank(ctx, arg, argf=None):
await ctx.message.delete() await del_message(ctx)
if argf is None: if argf is None:
try: try:
player = WATCHER.summoner.by_name(REGION, arg) player = WATCHER.summoner.by_name(REGION, arg)
@@ -129,7 +136,7 @@ async def rank(ctx, arg, argf=None):
embed.description = ranks embed.description = ranks
await ctx.send(embed=embed) await ctx.send(embed=embed)
except ApiError: except ApiError:
await ctx.send("The nickname is unknow.") await ctx.send("The nickname is unknown.")
else: else:
await ctx.send("If you are trying to use a nickname with spaces, please surround it with quotes.") 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 user = arg1
else: else:
user = ctx.message.author user = ctx.message.author
await ctx.message.delete() await del_message(ctx)
try: try:
voice_channel = user.voice.channel voice_channel = user.voice.channel
except AttributeError: except AttributeError: