問題描述
最近,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.
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 不會注冊新代碼...至少我的 phpstorm 目前沒有 :)
IDE won't register the new code...at least my php storm currently does'nt :)
但是,給予機器人正確的權限以使用這種類型的命令很重要!
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
這篇關于新的 Discord 斜線命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!