Skip to content

Commit acf523d

Browse files
committed
Added Cog example
1 parent db80d94 commit acf523d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Simple Discord Slash Command extension for [discord.py](https://github.com/Rapptz/discord.py).
33

44
## Example
5+
Normal usage:
56
```py
67
import discord
78
from discord.ext import commands
@@ -21,6 +22,33 @@ async def _test(ctx: SlashContext):
2122
bot.run("discord_token")
2223
```
2324

25+
Cog:
26+
```py
27+
import discord
28+
from discord.ext import commands
29+
from discord_slash import SlashCommand
30+
from discord_slash import SlashContext
31+
32+
33+
class Slash(commands.Cog):
34+
def __init__(self, bot):
35+
self.bot = bot
36+
self.slash = SlashCommand(bot, override_type=True)
37+
# Cog is only supported by commands ext, so just skip checking type.
38+
39+
@self.slash.slash(name="test")
40+
async def _test(ctx: SlashContext):
41+
await ctx.send(content="Hello, World!")
42+
43+
def cog_unload(self):
44+
self.slash.remove()
45+
46+
47+
def setup(bot):
48+
bot.add_cog(Slash(bot))
49+
50+
```
51+
2452
## Installation
2553
`pip install -U discord-py-slash-command`
2654

0 commit comments

Comments
 (0)