【问题标题】:Discord.js how use button several timesDiscord.js 如何多次使用按钮
【发布时间】:2022-01-10 16:30:31
【问题描述】:
const filter = (interaction) => {
    if (interaction.user.id === message.author.id) return true;
    return interaction.reply({
        content: "An error has occurred",
        ephemeral: true
    })
}

const collectorValue1 = message.channel.createMessageComponentCollector({
    filter,
    max: 1
})

collectorValue1.on("end", (ButtonInteraction) => {
    const id = ButtonInteraction.first().customId;
    if (id == '1') {
        ButtonInteraction.first().reply({
            content: "CONTENT",
            ephemeral: true
        })
    } else if (id == '2') {
        ButtonInteraction.first().reply({
            content: "CONTENT",
            ephemeral: true
        })
    } else if (id == '3') {
        ButtonInteraction.first().reply({
            content: "CONTENT.",
            ephemeral: true
        })

    }
})

我希望在创建按钮时它们是多个可执行文件,但是我只能使用该按钮一次,之后我总是收到消息“此交互失败”。如何使按钮具有多个可执行性?

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    我假设您是直接从其他人那里复制的,它没有工作,您决定先在这里询问,而不是查看代码。如果您没有直接编写代码,请努力理解代码。

    回答你的问题,代码:

    const collectorValue1 = message.channel.createMessageComponentCollector({filter, max: 1})
    

    正在创建一个最大响应数为 1 的收集器,请将数字更改为您希望按钮能够被点击的次数。

    你可以在MessageComponentCollectorOptionshere阅读更多内容

    【讨论】:

    • 我看懂了代码,但是当我增加数字然后尝试使用按钮时,总是出现“此交互失败”。当我增加它时,我不知何故根本无法使用它......
    猜你喜欢
    • 2021-11-24
    • 2014-06-30
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多