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
JavaScript
x
37
37
1
from IMPORTANT.keep_alive import keep_alive
2
import os
3
4
try:
5
from nextcord.ext import commands
6
from nextcord import Interaction
7
import nextcord
8
9
except ImportError:
10
os.system("pip install -U nextcord")
11
from nextcord.ext import commands
12
from nextcord import Interaction
13
import nextcord
14
15
intents = nextcord.Intents().all()
16
bot = commands.Bot(command_prefix="+", intents=intents)
17
bot.remove_command("help")
18
server = 896366068417830933
19
20
for file in os.listdir("./cogs/commands"):
21
if file.endswith(".py"):
22
name = file[:-3]
23
bot.load_extension(f"cogs.commands.{name}")
24
25
for file in os.listdir("./cogs/events"):
26
if file.endswith(".py"):
27
name = file[:-3]
28
bot.load_extension(f"cogs.events.{name}")
29
30
# slash command test
31
@bot.slash_command(name="test", description="commande de test", guild_ids=[server])
32
async def test(interaction: Interaction):
33
await interaction.response.send_message("les slashs commands fonctionnent")
34
35
keep_alive()
36
bot.run(os.getenv("TOKEN"))
37
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
if you are using the event “
on_interaction
“JavaScript131if interaction.type == InteractionType.application_command:
2await self.client.process_application_commands(interaction)
3
reinvite the bot with the following permission
applications.commands