【问题标题】:I can't figure out discord.js v13 buttons我不知道 discord.js v13 按钮
【发布时间】:2021-10-29 16:02:38
【问题描述】:

我只是不知道如何在 Discord.js v13 中发送与消息的按钮交互,在 v12 中你只是使用不和谐按钮,但这里它以某种方式内置,我不太明白。

【问题讨论】:

  • 请显示您已经尝试过的内容,包括任何错误/问题。如果您在设置时遇到问题,请参阅此问题答案中的链接。
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

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


【解决方案1】:
const { MessageActionRow, MessageButton } = require('discord.js');

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    if (interaction.commandName === 'ping') {
        const row = new MessageActionRow()
            .addComponents(
                new MessageButton()
                    .setCustomId('primary')
                    .setLabel('Primary')
                    .setStyle('PRIMARY'),
            );

        await interaction.reply({ content: 'Pong!', components: [row] });
    }
});

对于外部重定向按钮,您应该使用 .setLabel('LINK') 而不是 .setLabel('Primary'),然后删除 .setCustomId('primary')。添加 .setURL('URL')

For more click here

【讨论】:

    【解决方案2】:

    Discord.js 有一个很棒的文档,您可以在 Buttons Section 中找到更多关于按钮的信息。 它有据可查,也有一些很好的例子。

    【讨论】:

    • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
    猜你喜欢
    • 2021-12-02
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多