Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slashcommand cog example #9793

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/cog_basic.py
@@ -0,0 +1,24 @@
import discord
import random

from discord.ext import commands
from discord import app_commands

class Cog_basic(commands.Cog):
def __init__(self, bot):
self.bot = bot

@app_commands.command()
async def roll(self, ctx: discord.Interaction, dice: str):
"""Rolls a dice in NdN format."""
try:
rolls, limit = map(int, dice.split('d'))
except Exception:
await ctx.response.send_message('Format has to be in NdN!')
return

result = ', '.join(str(random.randint(1, limit)) for r in range(rolls))
await ctx.response.send_message(result)

async def setup(bot):
await bot.add_cog(Cog_basic(bot))