discord.js v13试图收集按钮并检查按钮ID
我正在尝试收集一个按钮,然后检查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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建 /a>您正在告诉它,以监视用户为任何按钮单击的第一个消息。由于按钮在
msg
变量而不是Message
变量中,因此您只需要将其更改为msg
即可。您的固定代码应该看起来像这样: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 themsg
variable instead of themessage
variable, you will just need to change that one tomsg
. Your fixed code should look like this: