【发布时间】:2022-01-03 03:46:32
【问题描述】:
点击这里
我想创建按钮,但我不知道该怎么做?谁能给我一个例子?我要不带包的
【问题讨论】:
-
Click Button 与 discord.js v13 一起发布,但尚未正式发布,您必须等待稳定
标签: discord discord.js
点击这里
我想创建按钮,但我不知道该怎么做?谁能给我一个例子?我要不带包的
【问题讨论】:
标签: discord discord.js
这是一个没有模块(只是 discord.js)的简单示例,用于创建一个简单的按钮并在点击时回复:
const { Client, MessageActionRow, MessageButton } = require('discord.js')
// The code... (the client.on('message') or .on('interactionCreate'))
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId("simple-example") // It is better to have a unique ID for the buttons
.setLabel("Text diplayed on the button")
.setStyle('PRIMARY'), //PRIMARY, SECONDARY, ALERT or SUCCESS
);
// For interactions do like this:
interaction.reply({ content: "Super button below", components: [row] })
// For messages do like this:
message.reply({ content: "Super button below", components: [row] })
client.on('interactionCreate', interaction => {
if (interaction.isButton()) {
if (interaction.customId === "simple-example") {
interaction.reply('Button clicked !')
}
}
})
// Log in with the bot
【讨论】: