From 1926b84090551cc60003f8bca536a6965a2e01e6 Mon Sep 17 00:00:00 2001 From: dnns01 <mail@dnns01.de> Date: Mon, 21 Dec 2020 15:38:34 +0100 Subject: [PATCH] Added feature to roll dice --- roll_cog.py | 19 +++++++++++++++++++ strolly.py | 6 ++++++ 2 files changed, 25 insertions(+) create mode 100644 roll_cog.py diff --git a/roll_cog.py b/roll_cog.py new file mode 100644 index 0000000..6bf3111 --- /dev/null +++ b/roll_cog.py @@ -0,0 +1,19 @@ +import random + +from discord.ext import commands + + +class RollCog(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command(name="roll") + async def cmd_roll(self, ctx, dice="w6", qty=1): + """ Roll a/multiple dice """ + + eyes = int(dice[1:]) + answer = f"Es wurden {qty} {dice.upper()} geworfen, mit folgenden Ergebnissen:\n" + for i in range(qty): + answer += f"{i + 1}. Wurf: {random.randrange(1, eyes + 1)}\n" + + await ctx.send(answer) diff --git a/strolly.py b/strolly.py index ab108e7..3b009f1 100644 --- a/strolly.py +++ b/strolly.py @@ -6,6 +6,7 @@ from dotenv import load_dotenv from bati_cog import BatiCog from poll_cog import PollCog +from roll_cog import RollCog # .env file is necessary in the same directory, that contains several strings. load_dotenv() @@ -17,6 +18,7 @@ intents = discord.Intents.default() intents.members = True bot = commands.Bot(command_prefix='!', help_command=None, activity=discord.Game(ACTIVITY), intents=intents) bot.add_cog(PollCog(bot)) +bot.add_cog(RollCog(bot)) bot.add_cog(BatiCog(bot)) @@ -33,6 +35,10 @@ bot.add_cog(BatiCog(bot)) @bot.event async def on_ready(): print("Client started!") + # channel = await bot.fetch_channel(682590504948334684) + # await channel.send("!poll \"Wie kluk bin ich?\" Sehr") +# + bot.run(TOKEN) -- GitLab