From b1f2e3ad39269c02a0f840ba80b5f4f4c7743857 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 28 May 2021 14:03:34 +0200 Subject: [PATCH] adding test cog for new slash commands --- requirements.txt | 1 + src/cogs/slash.py | 17 +++++++++++++++++ src/main.py | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 src/cogs/slash.py diff --git a/requirements.txt b/requirements.txt index 920fa85..2b3444a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ asyncpraw==7.2.0 # reddit youtube-dl==2021.4.26 # music lyricsgenius==3.0.1 # lyrics feedparser==6.0.2 # rss feed (news) +discord-py-slash-command==1.2.0 # slash commands diff --git a/src/cogs/slash.py b/src/cogs/slash.py new file mode 100644 index 0000000..ec5c133 --- /dev/null +++ b/src/cogs/slash.py @@ -0,0 +1,17 @@ +import discord +from discord.ext import commands +from discord_slash import cog_ext, SlashContext + +def setup(client): + client.add_cog(Slash(client)) + +class Slash(commands.Cog): + """Slash commands test.""" + + def __init__(self, client): + self.client = client + + @cog_ext.cog_slash(name="test") + async def _test(self, ctx: SlashContext): + embed = discord.Embed(title="embed test") + await ctx.send(content="test", embeds=[embed]) diff --git a/src/main.py b/src/main.py index 4db72ee..fdf7a32 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ print("Chargement des extensions & librairie...", end = " ") import discord, re, pytz, os +from discord_slash import SlashCommand from discord.ext import commands from random import choice from datetime import datetime @@ -9,6 +10,7 @@ customPrefix = os.environ['PREFIX'] customTimezone = os.environ['TIMEZONE'] client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all()) +slash = SlashCommand(client, sync_commands = True, sync_on_cog_reload = True) client.load_extension("cogs.help") client.load_extension("cogs.utils") @@ -18,6 +20,7 @@ client.load_extension("cogs.games") client.load_extension("cogs.fun") client.load_extension("cogs.autopublish") client.load_extension("cogs.school") +client.load_extension("cogs.slash") print("Terminé !") @client.event