【问题标题】:collector.on 'collect' event with button rows, discord js buttonscollector.on 带有按钮行的“收集”事件,不和谐的 js 按钮
【发布时间】:2021-10-17 02:05:54
【问题描述】:

我是第一次使用按钮行,我正在使用

这个

collector.on('collect', Button => {
        ...
});

对于我的按钮收集器(在带有 3 行按钮的消息上),就像我之前所做的那样

但我想它应该看起来有些不同,因为它运行但不识别按钮

【问题讨论】:

  • (node:15368) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emoji' of undefined

标签: javascript button discord rows


【解决方案1】:

当一个按钮被点击时,它会触发“interactionCreate”事件。因此,要过滤斜杠命令和您应该使用的消息组件:

client.on("interactionCreate", interaction => {
    if (interaction.type == "APPLICATION_COMMAND") {
        client.emit("slashCommand", interaction)
    }
    else if (interaction.type == "MESSAGE_COMPONENT") {
        client.emit("clickButton", interaction)
    }
}

然后你可以像这样创建 2 个收集器:

client.on("slashCommand", SlashCommand => {
    //your code
})

client.on("clickButton", Button => {
    //your code
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 2022-01-15
    • 2022-01-07
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多