randomizer cog
This commit is contained in:
8
cogs/random/config.json
Normal file
8
cogs/random/config.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"description": "Random number and choice generators.",
|
||||
"usages": [
|
||||
"rng [maximum]",
|
||||
"choose <option1> <option2> ..."
|
||||
],
|
||||
"hidden": false
|
||||
}
|
||||
35
cogs/random/random.py
Normal file
35
cogs/random/random.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import random
|
||||
import logging
|
||||
from discord.ext import commands
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class RandomizerCog(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
logger.info("Randomizer cog loaded successfully")
|
||||
|
||||
@commands.command(name="rng")
|
||||
async def rng(self, ctx: commands.Context, maximum: int = 100):
|
||||
if maximum < 1:
|
||||
await ctx.send("Please provide a maximum number greater than 0.")
|
||||
return
|
||||
|
||||
result = random.randint(1, maximum)
|
||||
await ctx.send(f" I rolled a **{result}** (from 1-{maximum}).")
|
||||
|
||||
@commands.command(name="choose")
|
||||
async def choose(self, ctx: commands.Context, *options: str):
|
||||
if not options:
|
||||
await ctx.send("No options provided.")
|
||||
return
|
||||
|
||||
if len(options) == 1:
|
||||
await ctx.send(f"I choose **{options[0]}**.")
|
||||
return
|
||||
|
||||
choice = random.choice(options)
|
||||
await ctx.send(f"Out of those options, I have chosen **{choice}**.")
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(RandomizerCog(bot))
|
||||
Reference in New Issue
Block a user