Skip to content

Commit d21446d

Browse files
committed
Format slash cog group example
1 parent 7c571b7 commit d21446d

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
1-
from discord.commands.permissions import Permission
21
import discord
3-
from discord.commands.commands import SlashCommandGroup
2+
from discord.commands import SlashCommandGroup, Permission
43
from discord.ext import commands
54

6-
# Set these
7-
GUILD_ID=0
8-
OWNER_ID=0
5+
bot = discord.Bot(debug_guild=..., owner_id=...) # main file
96

10-
bot = discord.Bot(debug_guild=GUILD_ID, owner_id=OWNER_ID)
117

128
class Example(commands.Cog):
139
def __init__(self, bot):
1410
self.bot = bot
1511

1612
greetings = SlashCommandGroup("greetings", "Various greeting from cogs!")
17-
international_greetings = greetings.command_group("international", "International greetings")
1813

19-
secret_greetings = SlashCommandGroup("secret_greetings", "Secret greetings", permissions=[
20-
Permission("owner", 2, True) # Ensures the owner_id user can access this, and no one else
21-
])
22-
14+
international_greetings = greetings.subgroup(
15+
"international", "International greetings"
16+
)
17+
18+
secret_greetings = SlashCommandGroup(
19+
"secret_greetings",
20+
"Secret greetings",
21+
permissions=[
22+
Permission(
23+
"owner", 2, True
24+
) # Ensures the owner_id user can access this, and no one else
25+
],
26+
)
27+
2328
@greetings.command()
2429
async def hello(self, ctx):
25-
await ctx.respond("Hi, this is a slash command from a cog!")
30+
await ctx.respond("Hello, this is a slash subcommand from a cog!")
2631

2732
@international_greetings.command()
2833
async def aloha(self, ctx):
2934
await ctx.respond("Aloha, a Hawaiian greeting")
30-
31-
32-
@greetings.command()
33-
async def hi(self, ctx):
34-
await ctx.respond(f"Hi, this is a slash sub-command from a cog!")
3535

3636
@secret_greetings.command()
3737
async def secret_handshake(self, ctx, member: discord.Member):
3838
await ctx.respond(f"{member.mention} secret handshakes you")
3939

4040

41-
bot.add_cog(Example(bot))
42-
43-
44-
bot.run("TOKEN")
41+
bot.add_cog(Example(bot)) # put in a setup function for cog files
42+
bot.run("TOKEN") # main file

0 commit comments

Comments
 (0)