【问题标题】:Button not working discord.js discord-buttons按钮不工作 discord.js discord-buttons
【发布时间】:2021-10-13 08:23:27
【问题描述】:

你好,所以我写了这段代码

module.exports.run = async (Client, message, args, prefix) => {
 
 if (!message.content.startsWith(prefix)) return;
  disbut(Client);
  let button1 = new disbut.MessageButton()
    .setStyle("green") //default: blurple
    .setLabel("créer un channel") //default: NO_LABEL_PROVIDED
    .setID("create"); //note: if you use the style "url" you must provide url using .setURL('https://example.com')
  let button2 = new disbut.MessageButton()
    .setStyle("red") //default: blurple
    .setLabel("fermer un channel") //default: NO_LABEL_PROVIDED
    .setID("close"); //note: if you use the style "url" you must provide url using .setURL('https://example.com')

  message.channel.send("Cliquer sur les boutons pour effectuer une action   ", {buttons : [button1, button2] });
};

如果我执行我的命令,文本会在我的频道中发送,而不是按钮 我不明白为什么,我没有任何错误

感谢您的帮助:)

【问题讨论】:

  • 我在文档中找到了添加多个按钮的方法:let row = new MessageActionRow().addComponents(button, button2);。然后发送带有消息的按钮send('msg', row)。试一试。
  • 而您返回的内容没有前缀 2 次。这样做的目的是什么?
  • 感谢您的回答,我会尽快尝试对于您的问题,我只是想念我的 ctrl-c ctrl-v 错误。
  • 我的问题是不添加多个按钮,我不能在我的消息上只添加一个按钮

标签: javascript node.js discord.js discord-buttons


【解决方案1】:

在 Discord.js v13 中,send 方法只接受一个参数。 Discord.js 只查看 "Cliquer sur les boutons..." 而不是您提供的第二个对象。

改为使用单个 MessageOptions 对象:

message.channel.send({
  content: "Cliquer sur les boutons pour effectuer une action   ",
  buttons: [button1, button2]
});

如需了解更多信息,请参阅this section in the Discord.js guide

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 2021-10-01
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2017-09-12
    相关资源
    最近更新 更多