Skip to content

Commit

Permalink
Added Cog example
Browse files Browse the repository at this point in the history
  • Loading branch information
eunwoo1104 committed Dec 16, 2020
1 parent db80d94 commit acf523d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Simple Discord Slash Command extension for [discord.py](https://github.com/Rapptz/discord.py).

## Example
Normal usage:
```py
import discord
from discord.ext import commands
Expand All @@ -21,6 +22,33 @@ async def _test(ctx: SlashContext):
bot.run("discord_token")
```

Cog:
```py
import discord
from discord.ext import commands
from discord_slash import SlashCommand
from discord_slash import SlashContext


class Slash(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.slash = SlashCommand(bot, override_type=True)
# Cog is only supported by commands ext, so just skip checking type.

@self.slash.slash(name="test")
async def _test(ctx: SlashContext):
await ctx.send(content="Hello, World!")

def cog_unload(self):
self.slash.remove()


def setup(bot):
bot.add_cog(Slash(bot))

```

## Installation
`pip install -U discord-py-slash-command`

Expand Down

0 comments on commit acf523d

Please sign in to comment.