Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Making a Slash Command appear in Discord UI

On discord, the module discord.ext.commands lets you create commands. I tried to create a command, with prefix="/", although it won’t appear in discord’s UI.

Code:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="/")

@bot.command(name="kick", description="Kick a user to your wish.")
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.send(f"The user @{member} has been kicked. Reason: {reason}.")

bot.run("mytoken")

It won’t pop up.
no pop-up

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But I want to do it like this:
enter image description here

>Solution :

You need to install discord-py-slash-command and then put the code to import it from discord-py-slash-command import SlashCommands. You can refer the code below:

import discord
from discord_slash import SlashCommand
client = discord.Client(intents=discord.Intents.all())
slash = SlashCommand(client, sync_commands=True) # Declares slash commands through the client.

guild_ids = [1234567890] # Put your server IDs in this array.

@slash.slash(name="ping", guild_ids=guild_ids)
async def _ping(ctx):
    await ctx.send("Pong!")

client.run("token")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading