我創建了一個簡單的斜線命令。它適用于唯一的公會。在此之前,我使用的是 v12。現在我想切換到 v13。現在如何制作這些全域斜杠命令?
代碼
client.on ("ready", () => {
console.log(`${client.user.tag} Has logged in`)
client.user.setActivity(`/help | ${client.user.username}`, { type: "PLAYING" })
const guildId = "914573324485541928"
const guild = client.guilds.cache.get(guildId)
let commands
if (guild) {
commands = guild.commands
} else {
commands = client.application.commands
}
commands.create({
name: 'ping',
description: 'Replies with pong'
})
commands.create({
name: 'truth',
description: 'Replies with truth'
})
});
client.on('interactionCreate', async (interaction) => {
if(!interaction.isCommand()){
return
}
const { commandName, options } = interaction
if (commandName === 'ping'){
interaction.reply({
content: 'pong'
})
}
```
I'm new in v13 so please explain it simply :|
uj5u.com熱心網友回復:
只需更改guild宣告即可。您的代碼檢查是否guild為真,如果是,則使用公會。否則,它將使用全域命令
const guild = null
// any falsy value is fine (undefined, false, 0, '', etc.)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/368943.html
標籤:javascript 不和谐 不和谐.js
下一篇:如何將兩列文本合并為一列?
