From 718ac774d2ac7f194b9f067c8d8582abc05436cf Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 1 Jun 2021 00:27:16 +0200 Subject: [PATCH] ajout commande random --- src/cogs/fun.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/cogs/fun.py b/src/cogs/fun.py index c68ff7c..5e95f04 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -178,3 +178,30 @@ class Fun(commands.Cog): return await ctx.send("".join(message).replace("\\N", "\n").replace("\\n", "\n")) else: return await ctx.send("Le message ne contient aucun texte.", delete_after = 5) + + @commands.command(name='random', aliases=['randint']) + async def _random(self, ctx, *n): + """Tire au hasard un chiffre entre 1 et n (par défaut n=10)\n ➡ Syntaxe: {PREFIX}random/randint [n]""" + fromSlash = False + if len(n) > 0: + if n[-1] == True: + fromSlash = n[-1] + n = n[:-1] + if len(n) > 0: + try: + n = int(n[0]) + except: + return await ctx.send("Veuillez renseigner un chiffre valide.") + else: + n = 10 + + resultat = randint(1, n) + if fromSlash != True: + await ctx.message.add_reaction(emoji = '✅') + return await ctx.send(embed = discord.Embed().set_author(name = f"Tu as tiré le chiffre {resultat} !")) + @cog_ext.cog_slash(name="random", description = "Tire au hasard un chiffre entre 1 et n (par défaut n=10)") + async def __random(self, ctx, n: int = None): + if n == None: + await self._random(ctx, True) + else: + await self._random(ctx, n, True)