Skip to content

Commit e3bde55

Browse files
authored
Merge pull request #341 from Sengolda/patch-2
Add example for slash commands in cogs.
2 parents 26c85e4 + 5af5556 commit e3bde55

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

examples/app_commands/slash_cog.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from discord.ext import commands
2+
from discord.commands import slash_command # Importing the decorator that makes slash commands.
3+
4+
class Example(commands.Cog):
5+
def __init__(self, bot):
6+
self.bot = bot
7+
8+
@slash_command(guild_ids=[...]) # Create a slash command for the supplied guilds.
9+
async def hello(self, ctx):
10+
await ctx.respond("Hi, this is a slash command from a cog!")
11+
12+
13+
@slash_command() # Not passing in guild_ids creates a global slash command (might take an hour to register).
14+
async def hi(self, ctx):
15+
await ctx.respond(f"Hi, this is a global slash command from a cog!")
16+
17+
def setup(bot):
18+
bot.add_cog(Example(bot))

0 commit comments

Comments
 (0)