【问题标题】:creating message component (Button) discord.js创建消息组件(按钮)discord.js
【发布时间】:2022-01-03 03:46:32
【问题描述】:

点击这里

我想创建按钮,但我不知道该怎么做?谁能给我一个例子?我要不带包的

【问题讨论】:

  • Click Button 与 discord.js v13 一起发布,但尚未正式发布,您必须等待稳定

标签: discord discord.js


【解决方案1】:

这是一个没有模块(只是 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

【讨论】:

  • 对于 LINK 样式不能回复按钮交互但需要指定 .setURL('example.com')
猜你喜欢
  • 2010-10-08
  • 1970-01-01
  • 2016-03-11
  • 2020-07-04
  • 1970-01-01
  • 2021-02-05
  • 1970-01-01
  • 2021-08-15
  • 2018-02-28
相关资源
最近更新 更多