Justin
Justin

Reputation: 23

Discord.py | Slash commands aren’t working

I’m trying to have my discord bot (using discord.py) support slash commands like this picture shown. enter image description here

I already have installed discord-py-slash-command, put the code to import it from discord-py-slash-command import SlashCommands and invited my bot using the application.commands. I have this code shown. (I’m trying to add the slash to the ping command)

import discord
from discord.ext import Commands
from discord-py-slash-command import SlashCommands

client = commands.Bot(commands_prefix=“.”)

@client.commands(description=“Ping”)
async def ping(ctx):
     await ctx.send(“Pong!”)

client.run(“MY_TOKEN”)

I also tried @client.commands.slash

I’m new to this slash thing. Help?

Upvotes: 0

Views: 10703

Answers (1)

Benjin
Benjin

Reputation: 3495

The Quickstart page has example code on how to create slash commands.

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")

Upvotes: 4

Related Questions