Skip to content
Advertisement

Nextcord Slash Commands

I’ve heard that nextcord has now slash commands! That’s great, and this is why I want to add them in my bot. I’ve already watched YouTube tutorials, but, for some reason, it doesn’t work. This is my main.py file

from IMPORTANT.keep_alive import keep_alive
import os

try:
    from nextcord.ext import commands
    from nextcord import Interaction
    import nextcord
    
except ImportError:
    os.system("pip install -U nextcord")
    from nextcord.ext import commands
    from nextcord import Interaction
    import nextcord

intents = nextcord.Intents().all()
bot = commands.Bot(command_prefix="+", intents=intents)
bot.remove_command("help")
server = 896366068417830933

for file in os.listdir("./cogs/commands"):
    if file.endswith(".py"): 
        name = file[:-3]
        bot.load_extension(f"cogs.commands.{name}") 

for file in os.listdir("./cogs/events"):
    if file.endswith(".py"): 
        name = file[:-3]
        bot.load_extension(f"cogs.events.{name}") 
    
# slash command test
@bot.slash_command(name="test", description="commande de test", guild_ids=[server])
async def test(interaction: Interaction):
    await interaction.response.send_message("les slashs commands fonctionnent")

keep_alive()
bot.run(os.getenv("TOKEN"))

EDIT: Idk if it changes something but I use repl.it

Advertisement

Answer

I tried your code and it works for me. Maybe this will fix it

  1. if you are using the event “on_interaction

    if interaction.type == InteractionType.application_command:
    await self.client.process_application_commands(interaction)
    
  2. reinvite the bot with the following permission

    applications.commands

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement