nextcord 上的斜杠命令

Slash commands on nextcord

我想添加斜杠命令但没有成功。经过数小时的文档阅读、示例检查后,我终于放弃了在我当前的代码上尝试它的想法。所以我随便尝试了 nextcord 文档中的示例代码。我 copy/paste 代码添加令牌和公会 ID。但这并没有更成功。 我的机器人有管理员权限(范围内有 8 个),意图都是在机器人开发面板上检查,经过数小时的等待……斜线列表上没有任何内容。我认为这是我的 discord 客户端的刷新问题,所以我在多个设备(pc、mac、phone、...)上测试了 运行 discord,但没有。

正如我所说,我尝试了仅更改了服务器 ID 的示例代码(并且还正确编辑了令牌,机器人本身 运行 运行良好)

import nextcord

client = nextcord.Client()
server = numberfromguildid


@client.slash_command(guild_ids=[server])  # limits guilds with this command.
async def ping(
    interaction: nextcord.Interaction,
):
    await interaction.response.send_message("Pong!")


client.run("TOKEN")

如果有人有解决方案可以挽救生命!

您在生成 OAuth2 link 时是否启用了 applications command?并且您仍然需要从 nextcordnextcord.abc 导入模块,您的代码应该如下所示:

from nextcord import Interaction, SlashOption, ChannelType
from nextcord.abc import GuildChannel
from nextcord.ext import commands
import nextcord

我猜你启动客户端的方式似乎也是错误的

client = commands.Bot(command_prefix='YOUR_PREFIX')