mirror of
https://github.com/Floriansylvain/Risitas_BOT.git
synced 2026-08-19 11:43:16 +02:00
🥅 - Commands errors are now treaded in a better way.
This commit is contained in:
+4
-22
@@ -11,12 +11,9 @@ class LolCmds(commands.Cog, name='League of Legend commands'):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command()
|
||||
@commands.command(ignore_extra=False)
|
||||
@commands.cooldown(1, 2, commands.BucketType.user)
|
||||
async def lol_rank(self, ctx, invocator_name, x=None):
|
||||
global CD_LOLRANK
|
||||
CD_LOLRANK = 0
|
||||
if x is None:
|
||||
async def lol_rank(self, ctx, invocator_name):
|
||||
player = what_player(invocator_name)
|
||||
if player != 0:
|
||||
ranks = rank_track(player)
|
||||
@@ -35,13 +32,10 @@ class LolCmds(commands.Cog, name='League of Legend commands'):
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send('The username you entered is unknown.')
|
||||
else:
|
||||
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
|
||||
|
||||
|
||||
@commands.command()
|
||||
async def lol_lastgame(self, ctx, invocator_name, x=None):
|
||||
if x is None:
|
||||
@commands.command(ignore_extra=False)
|
||||
async def lol_lastgame(self, ctx, invocator_name):
|
||||
player = what_player(invocator_name)
|
||||
if player != 0:
|
||||
lst = last_match(player)
|
||||
@@ -79,18 +73,6 @@ class LolCmds(commands.Cog, name='League of Legend commands'):
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send('The username you entered is unknown.')
|
||||
else:
|
||||
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
|
||||
|
||||
|
||||
@lol_rank.error
|
||||
async def lolrank_error(self, ctx, error):
|
||||
global CD_LOLRANK
|
||||
if isinstance(error, commands.CommandOnCooldown) and not CD_LOLRANK:
|
||||
await ctx.send(f'Please wait at least 2 seconds between each $lol_rank.')
|
||||
CD_LOLRANK = 1
|
||||
elif isinstance(error, commands.MissingRequiredArgument):
|
||||
await ctx.send(f'Please enter an invocator name (EUW) after $lol_rank.')
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
||||
+6
-15
@@ -8,9 +8,8 @@ class OsuCmds(commands.Cog, name='Osu! commands'):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command()
|
||||
async def osu_profile(self, ctx, username, x=None):
|
||||
if x is None:
|
||||
@commands.command(ignore_extra=False)
|
||||
async def osu_profile(self, ctx, username):
|
||||
lst = await ask_osu_profile(username)
|
||||
if lst == 1:
|
||||
await ctx.send('The username you entered is unknown.')
|
||||
@@ -32,13 +31,10 @@ class OsuCmds(commands.Cog, name='Osu! commands'):
|
||||
embed.add_field(name='Total Score', value=str('{:,}'.format(lst[4])))
|
||||
embed.add_field(name='Total Hits', value=str('{:,}'.format(lst[5])))
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
|
||||
|
||||
|
||||
@commands.command()
|
||||
async def osu_lastgame(self, ctx, username, x=None):
|
||||
if x is None:
|
||||
@commands.command(ignore_extra=False)
|
||||
async def osu_lastgame(self, ctx, username):
|
||||
lst = await ask_osu_last_game(username)
|
||||
if lst == 1:
|
||||
await ctx.send('The player you entered is unknown or didn\'t played any game recently.')
|
||||
@@ -64,13 +60,10 @@ class OsuCmds(commands.Cog, name='Osu! commands'):
|
||||
embed.add_field(name='Miss', value=str(lst[15]))
|
||||
embed.add_field(name='|', value='|')
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
|
||||
|
||||
|
||||
@commands.command()
|
||||
async def osu_acc(self, ctx, username, x=None):
|
||||
if x is None:
|
||||
@commands.command(ignore_extra=False)
|
||||
async def osu_acc(self, ctx, username):
|
||||
test_acc = await ask_osu_acc(username)
|
||||
if test_acc:
|
||||
embed = discord.Embed()
|
||||
@@ -79,8 +72,6 @@ class OsuCmds(commands.Cog, name='Osu! commands'):
|
||||
await ctx.send(embed=embed, file=discord.File('acc.jpeg'))
|
||||
else:
|
||||
await ctx.send('The player you entered is unknown or didn\'t played any game recently.')
|
||||
else:
|
||||
await ctx.send('If you are trying to use a username with spaces, please surround it with quotes.')
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
||||
+1
-12
@@ -3,13 +3,12 @@ import asyncio
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands.cooldowns import BucketType
|
||||
|
||||
CD_ISSOU = 0
|
||||
|
||||
class OtherCmds(commands.Cog, name='Other commands'):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command()
|
||||
@commands.command(ignore_extra=False)
|
||||
@commands.cooldown(1, 2, commands.BucketType.guild)
|
||||
async def issou(self, ctx, username: discord.User = None):
|
||||
if username is not None:
|
||||
@@ -31,19 +30,9 @@ class OtherCmds(commands.Cog, name='Other commands'):
|
||||
if voice.is_playing():
|
||||
await asyncio.sleep(1)
|
||||
await voice.disconnect()
|
||||
global CD_ISSOU
|
||||
CD_ISSOU = 0
|
||||
else:
|
||||
await ctx.send('You or the targeted person are not connected to any channel.')
|
||||
|
||||
|
||||
@issou.error
|
||||
async def issou_error(self, ctx, error):
|
||||
global CD_ISSOU
|
||||
if isinstance(error, commands.CommandOnCooldown) and not CD_ISSOU:
|
||||
await ctx.send(f'Please wait at least 2 seconds between each $issou.')
|
||||
CD_ISSOU = 1
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(OtherCmds(bot))
|
||||
|
||||
@@ -74,7 +74,7 @@ class TwitchCmds(commands.Cog, name='Twitch commands'):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command()
|
||||
@commands.command(ignore_extra=False)
|
||||
async def chat_set(self, ctx, channel_name):
|
||||
try:
|
||||
await ctx.message.delete()
|
||||
|
||||
+13
-19
@@ -1,13 +1,16 @@
|
||||
from private import TOKEN_BOT
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
from discord.ext import commands
|
||||
import discord
|
||||
|
||||
|
||||
bot = commands.Bot(command_prefix='$')
|
||||
startup_extensions = ["cmd_other", "cmd_lol", "cmd_osu", "cmd_twitch"]
|
||||
time_s = time()
|
||||
print('Loading started')
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
default_activity = discord.Activity(type=discord.ActivityType.listening, name='$help')
|
||||
@@ -16,33 +19,24 @@ async def on_ready():
|
||||
' in ' + str(round(time() - time_s, 2)) + 's.')
|
||||
|
||||
|
||||
@bot.command(hidden=True)
|
||||
@bot.event
|
||||
async def on_command_error(ctx, error):
|
||||
print(datetime.now().strftime("[%H:%M:%S]") + ' \'' + str(error) + '\' from ' + str(ctx.author) + ' on ' + ctx.message.guild.name + '.')
|
||||
await ctx.send(error)
|
||||
|
||||
|
||||
@bot.command(hidden=True, ignore_extra=False)
|
||||
@commands.is_owner()
|
||||
async def loadext(ctx, extension):
|
||||
try:
|
||||
bot.load_extension(extension)
|
||||
await ctx.send(str(extension) + ' successfully loaded.')
|
||||
except discord.ext.commands.ExtensionNotFound:
|
||||
await ctx.send('Extension not found.')
|
||||
except discord.ext.commands.ExtensionAlreadyLoaded:
|
||||
await ctx.send('Extension already loaded.')
|
||||
except discord.ext.commands.NoEntryPointError as a:
|
||||
await ctx.send(a)
|
||||
except ExtensionFailed as b:
|
||||
await ctx.send(b)
|
||||
await ctx.send("Extension loaded.")
|
||||
|
||||
|
||||
@bot.command(hidden=True)
|
||||
@bot.command(hidden=True, ignore_extra=False)
|
||||
@commands.is_owner()
|
||||
async def unloadext(ctx, extension):
|
||||
try:
|
||||
bot.unload_extension(extension)
|
||||
await ctx.send(str(extension) + ' successfully unloaded.')
|
||||
except discord.ext.commands.ExtensionNotFound:
|
||||
await ctx.send('Extension not found.')
|
||||
except discord.ext.commands.ExtensionNotLoaded:
|
||||
await ctx.send('Extension not loaded.')
|
||||
|
||||
await ctx.send("Extension unloaded.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
for extension in startup_extensions:
|
||||
|
||||
Reference in New Issue
Block a user