From acf523df7328f14b4a1bba24ccda1574d864fb89 Mon Sep 17 00:00:00 2001 From: eunwoo1104 Date: Wed, 16 Dec 2020 21:05:09 +0900 Subject: [PATCH] Added Cog example --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 12617636e..5e7872b78 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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`