【发布时间】:2021-12-31 13:07:01
【问题描述】:
我正在关注 V13 上不和谐斜线命令的教程,运行时没有错误,但是当我执行 /ping 时,它说交互失败。我查看了文档所需的权限,但看起来我获得了运行它所需的所有权限,即机器人和应用程序命令。
这是我的机器人代码:
import DiscordJS, { Intents, Interaction } from 'discord.js'
import dotenv from 'dotenv'
dotenv.config()
const client = new DiscordJS.Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
client.on('ready', () => {
console.log('The bot is ready')
const guildID = '906389171806040114'
const guild = client.guilds.cache.get(guildID)
let commands
if (guild) {
commands = guild.commands
} else {
commands = client.application?.commands
}
commands?.create({
name: 'pig',
description: 'Replies with pong',
})
commands?.create
})
client.on('interactCreate', async (Interaction) => {
if (!Interaction.isCommand()) {
return
}
const { commandName, options } = Interaction
if ( commandName === 'pig') {
Interaction.reply({
content: 'pong',
ephemeral: true,
})
}
})
client.login(process.env.TOKEN)
【问题讨论】:
标签: javascript node.js discord discord.js