|
1 |
| -from discord.commands.permissions import Permission |
2 | 1 | import discord
|
3 |
| -from discord.commands.commands import SlashCommandGroup |
| 2 | +from discord.commands import SlashCommandGroup, Permission |
4 | 3 | from discord.ext import commands
|
5 | 4 |
|
6 |
| -# Set these |
7 |
| -GUILD_ID=0 |
8 |
| -OWNER_ID=0 |
| 5 | +bot = discord.Bot(debug_guild=..., owner_id=...) # main file |
9 | 6 |
|
10 |
| -bot = discord.Bot(debug_guild=GUILD_ID, owner_id=OWNER_ID) |
11 | 7 |
|
12 | 8 | class Example(commands.Cog):
|
13 | 9 | def __init__(self, bot):
|
14 | 10 | self.bot = bot
|
15 | 11 |
|
16 | 12 | greetings = SlashCommandGroup("greetings", "Various greeting from cogs!")
|
17 |
| - international_greetings = greetings.command_group("international", "International greetings") |
18 | 13 |
|
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 | + |
23 | 28 | @greetings.command()
|
24 | 29 | 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!") |
26 | 31 |
|
27 | 32 | @international_greetings.command()
|
28 | 33 | async def aloha(self, ctx):
|
29 | 34 | 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!") |
35 | 35 |
|
36 | 36 | @secret_greetings.command()
|
37 | 37 | async def secret_handshake(self, ctx, member: discord.Member):
|
38 | 38 | await ctx.respond(f"{member.mention} secret handshakes you")
|
39 | 39 |
|
40 | 40 |
|
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