# Name according to your cog (e.g a random number generator -> RandomNumber)
classExample(commands.Cog):
# __init__ method is required with these exact parameters
def__init__(self,bot:discord.ext.commands.Bot):# type hinting (aka : discord.ext.commands.Bot) isn't necessary, but provides better intellisense in code editors
self.bot:discord.ext.commands.Bot=bot
# a basic ping slash command which utilizes embeds
@app_commands.command(name="ping",description="A command that sends a ping!")
# Shows how to get parameters, and how to send messages using goobers message thing
@commands.command()
asyncdefrandom_number(self,ctx:commands.Context,minimum:int|None,maximum:int|None):# every argument after ctx is a part of the command, aka "g.random_number 0 5" would set minimum as 0 and maximum as 5
# We should always assume that command parameters are None, since someone can gall g.randon_number.
ifminimumisNone:
awaitsend_message(ctx,message="Please specify the minimum number!")
return# make sure we dont continue
ifmaximumisNone:
awaitsend_message(ctx,message="Please specify the maximum number!")
return# make sure we dont continue
number=random.randint(minimum,maximum)
example_embed=discord.Embed(
title="Random number generator",
description=f"Random number: {number}",
color=discord.Color.blue(),
)
example_embed.set_footer(
text=f"Requested by {ctx.author.name}",
icon_url=ctx.author.display_avatar,
)
awaitsend_message(ctx,embed=example_embed)
# A command which requires the executor to be an admin, and takes a discord user as an argument
@requires_admin()# from modules.permission import requires_admin