我听说nextcord现在有斜杠命令了!太好了,这就是为什么我想把它们加到我的机器人里。我已经看过YouTube教程了,但由于某种原因,它不起作用。这是我的main.py文件
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"))编辑: Idk如果它改变了什么,但我使用repl.it
发布于 2022-01-16 17:23:20
我试过你的代码,它对我有用。也许这个能治好它
如果您使用的是事件“
on_interaction如果self.client.process_application_commands(interaction) interaction.type == InteractionType.application_command:等待
applications.commands
发布于 2022-01-23 15:43:01
问题可能在于,通过查看您的代码,您使命令名为"commande de test"和斜杠命令不会那样工作,除非您使用所谓的子命令,所以我认为只需调用命令test或其他什么。
发布于 2022-01-23 17:46:12
applications.commands (邀请链接,这就像bot范围)。任何用户都需要重新使用--不需要踢机器人,只需要重用链接。
https://stackoverflow.com/questions/70732110
复制相似问题