discord.js v13试图收集按钮并检查按钮ID

发布于 2025-02-09 00:49:01 字数 570 浏览 1 评论 0原文

我正在尝试收集一个按钮,然后检查button.id是否现金,这是我的代码

      const msg = message.reply({embeds: [dembed], components: [row1, row2]}).then(function (msg) {

        const filter = i => {
          i.deferUpdate();
          return i.user.id === message.author.id;
        };
        
        const collector = message.createMessageComponentCollector({ componentType: 'BUTTON', filter ,time: 15000 });

        collector.on('collect', i => {

          if(i.customId === 'cash') {
            msg.channel.send("test")
          }
        })

        })

I am trying to collect a button and then check if button.id is cash , here is my code

      const msg = message.reply({embeds: [dembed], components: [row1, row2]}).then(function (msg) {

        const filter = i => {
          i.deferUpdate();
          return i.user.id === message.author.id;
        };
        
        const collector = message.createMessageComponentCollector({ componentType: 'BUTTON', filter ,time: 15000 });

        collector.on('collect', i => {

          if(i.customId === 'cash') {
            msg.channel.send("test")
          }
        })

        })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撕心裂肺的伤痛 2025-02-16 00:49:01

创建 /a>您正在告诉它,以监视用户为任何按钮单击的第一个消息。由于按钮在msg变量而不是Message变量中,因此您只需要将其更改为msg即可。您的固定代码应该看起来像这样:

const msg = message.reply({ embeds: [dembed], components: [row1, row2] }).then(function (msg) {
    const filter = i => {
        i.deferUpdate();
        return i.user.id === message.author.id;
    };
    const collector = msg.createMessageComponentCollector({ componentType: 'BUTTON', filter, time: 15000 });
    collector.on('collect', i => {
        if (i.customId === 'cash') {
            msg.channel.send("test")
        }
    })

})

When creating the messageComponentCollector you are telling it to monitor the first message which the user posted for any button clicks. Since the buttons are in the msg variable instead of the message variable, you will just need to change that one to msg. Your fixed code should look like this:

const msg = message.reply({ embeds: [dembed], components: [row1, row2] }).then(function (msg) {
    const filter = i => {
        i.deferUpdate();
        return i.user.id === message.author.id;
    };
    const collector = msg.createMessageComponentCollector({ componentType: 'BUTTON', filter, time: 15000 });
    collector.on('collect', i => {
        if (i.customId === 'cash') {
            msg.channel.send("test")
        }
    })

})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文