Reputation:
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
Upvotes: 1
Views: 5705
Reputation: 9
applications.commands
(Invite link, it's like the bot
scope). Any users will also need to reauth - no need to kick the bot, just reuse the linkUpvotes: 0
Reputation: 29
The problem could be because, by looking at your code you made the command name "commande de test"
and slash commands don't work that way unless you use what is called sub-commands, so I would say just call the command test
or something.
Upvotes: 0
Reputation: 61
I tried your code and it works for me. Maybe this will fix it
if you are using the event "on_interaction
"
if interaction.type == InteractionType.application_command:
await self.client.process_application_commands(interaction)
reinvite the bot with the following permission
applications.commands
Upvotes: 1