'Slash Commands in nextcord

I am trying to make slash commands in my bot. However when I run the bot, the slash commands dont appear, I've tried reinviting the bot too. Here it my current code

@client.slash_command(name="ping", description="Check bots ping!")
async def pingtest(interaction : Interaction):
    await interaction.response.send_message(f"My ping is {round(client.latency * 1000)}ms")

And yes I do have the correct imports, because I know you need special imports for slash commands, and I have the latest version of nextcord.



Solution 1:[1]

There can be a few issues here.

  1. You haven't enabled all necessary permissions in the invite creator. You need to have bot and application.commands enabled

  2. You haven't waited an hour. The Discord API requires all slash commands to take about an hour to update when you run your code. This can be avoided if you are just testing or building for one server at the moment. Here's how.

serverID = serverIDYouAreTestingOnAsAnIntegerValue

@client.slash_command(name="ping", description="Check bots ping!", guild_ids=serverID)
async def pingtest(interaction : Interaction):
    await interaction.response.send_message(f"My ping is {round(client.latency * 1000)}ms")
  1. Quite a simple bug, if you are testing on a guild that is not yours, you may not have slash command permissions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dre