From fcb72c122506833980e3115af5d2e3afa5ee2930 Mon Sep 17 00:00:00 2001 From: iDutchy <42503862+iDutchy@users.noreply.github.com> Date: Thu, 2 Sep 2021 02:16:01 +0200 Subject: [PATCH 1/2] Create slash_only.py Basic example for slash commands --- examples/slash_commands/slash_only.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/slash_commands/slash_only.py diff --git a/examples/slash_commands/slash_only.py b/examples/slash_commands/slash_only.py new file mode 100644 index 00000000..22c7fe26 --- /dev/null +++ b/examples/slash_commands/slash_only.py @@ -0,0 +1,26 @@ +from discord.ext.commands import Bot, Cog, Option + +bot = Bot(slash_commands=True, normal_commands=False) # Setting normal_commands to False will make this slash commands only +bot.add_cog(Info(bot)) + +@bot.command(slash=True) +async def hello(ctx): + await ctx.send(f"Hey, {ctx.author.mention}!") + +# And in a cog + +class Info(Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command(slash=True) + async def userinfo(self, ctx, member: discord.Member = Option(description="The user to get info about")): # Note that it must use the description kwarg + """Get info about a member""" + await ctx.send(f"ID: {member.id}") + + @commands.command(slash=True) + async def ban(self, ctx, member: discord.Member = Option(description="The member to ban"), reason: str = Option("No reason", description="Why to ban them")): # The first arg here will be used as default if nothing was provided + await member.ban(reason=reason) + await ctx.send("They have been banned", ephemeral=True) + +bot.run("token") From 15f04aa0d2e71b390248c876a3caab152660c777 Mon Sep 17 00:00:00 2001 From: iDutchy <42503862+iDutchy@users.noreply.github.com> Date: Thu, 2 Sep 2021 02:18:33 +0200 Subject: [PATCH 2/2] Create slash_and_message.py Basic example for mixed commands --- examples/slash_commands/slash_and_message.py | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/slash_commands/slash_and_message.py diff --git a/examples/slash_commands/slash_and_message.py b/examples/slash_commands/slash_and_message.py new file mode 100644 index 00000000..87b89fa3 --- /dev/null +++ b/examples/slash_commands/slash_and_message.py @@ -0,0 +1,30 @@ +from discord.ext.commands import Bot, Cog, Option + +bot = Bot(slash_commands=True) # To use both normal and slash commands, you only need to enable slash commands +bot.add_cog(Info(bot)) + +@bot.command(slash=True) +async def hello(ctx): + await ctx.send(f"Hey, {ctx.author.mention}!") + +@bot.command() +async def byw(ctx): + await ctx.send(f"Bye {ctx.author.mention}!") + +# And in a cog + +class Info(Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command(slash=True) + async def userinfo(self, ctx, member: discord.Member = Option(description="The user to get info about")): # Note that it must use the description kwarg + """Get info about a member""" + await ctx.send(f"ID: {member.id}", ephemeral=True) + + @commands.command() + async def ban(self, ctx, member: discord.Member, reason: str = "No reason"): + await member.ban(reason=reason) + await ctx.send("They have been banned") + +bot.run("token")