新的Discord斜杠命令 [英] New Discord Slash Commands
问题描述
最近,discord为您自己的应用程序添加了对斜杠命令的支持.我通读了它的文档,并尝试搜索一些视频(但是该功能只是出现了),但我不明白我需要做什么才能使其正常工作.我正在使用WebStorm(js,node.js).有没有人成功地执行斜杠命令,如果是,怎么做?
Recently, discord added support for slash commands for your own application. I read through the documentation for it, and I've tried to search for some videos (however the feature did JUST come out) but I do not understand what I actually have to do to get it working. I am using WebStorm (js, node.js). Has anyone successfully made a slash command, and if so, how?
推荐答案
您可以使用常规的 discord.js
,现在使用其 v12.5.1
.
You can use the regular discord.js
, by now its v12.5.1
.
这只是一个示例,但对我有用.(目前,我正在尝试对此进行改进)
This is just a sample, but worked for me. (Currently i try to improve this)
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
client.api.applications(client.user.id).guilds(YOUR_GUILD_ID_HERE).commands.post({
data: {
name: "hello",
description: "hello world command"
// possible options here e.g. options: [{...}]
}
});
client.ws.on('INTERACTION_CREATE', async interaction => {
const command = interaction.data.name.toLowerCase();
const args = interaction.data.options;
if (command === 'hello'){
// here you could do anything. in this sample
// i reply with an api interaction
client.api.interactions(interaction.id, interaction.token).callback.post({
data: {
type: 4,
data: {
content: "hello world!!!"
}
}
})
}
});
});
client.login(token);
您当然可以选择,请参阅文档...
Of course you can have options, see documentation...
IDE不会注册新代码...至少我的PHP风暴目前没有:)
IDE won't register the new code...at least my php storm currently does'nt :)
但是,授予bot正确的权限以使用这种类型的命令很重要!
However, its important to give the bot the correct permissions to use this type of command!
因此,请转到 Discord.com/developers ,选择您的应用程序,然后转到 OAuth2
并选择
So go to Discord.com/developers, select your application, go to OAuth2
and select
application.commands
application.commands
从范围部分.这应该在中间列的底部.您还应该选择 bot
,然后在 Bot Permissions
下设置一些其他特定权限.然后使用该新的邀请链接重新邀请漫游器.
from the scope section. This should be at the bottom of the middle column. You should select bot
as well and under Bot Permissions
you set some other specific permissions. Then use that new invite link to reinvite the bot.
没有 application.commands
权限,该命令将不起作用,并且您会收到诸如 Missing Access
或类似错误之类的错误.
Without application.commands
permission, the command won't work and you will receive some error like Missing Access
or some similar.
重要事项
-
使用
.guilds('11231 ...').comma
测试这些命令.不使用此功能时,大约需要1小时才能激活.使用它会立即将其激活.
Use
.guilds('11231...').comma
to test these commands. When not using this, it takes round about 1h to get active. Using it will activate it immediately.
为漫游器授予正确的权限. application.commands
Give the bot the correct permission. application.commands
这篇关于新的Discord斜杠命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!