【发布时间】:2021-12-10 21:02:29
【问题描述】:
我是 javascript 的初学者,尤其是 discord.js 在了解了 discord.js 指南之后,我仍然无法让收集器工作。
client.on('interactionCreate', interaction => {
if (!interaction.isButton()) return;
const filter = i => i.customId === '1' || i.customId === "2";
const collectchannel = interaction.channel;
const collector = collectchannel.createMessageComponentCollector( filter, { time: 10000 });
collector.on('collect', i => {
if (i.customId === '1') {
client.commands.get('help').execute(interaction, 1, Discord);
} else if (i.customId === '2') {
client.commands.get('help').execute(interaction, 2, Discord);
}
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} interactions.`);
});
});
当我按下我的按钮时,收集功能不会做任何事情。我尝试放置一个console.log("test"),但它没有触发。但是,collector.on('end', collected => { 实际上会触发。
这可能是因为我不是一个好的程序员。如果可以,请帮忙!
【问题讨论】:
-
请提供足够的代码,以便其他人更好地理解或重现问题。
-
您确定交互 ID 正确吗?尝试在
collect事件中的两个 if 之前放置一个console.log(i.customId); -
@Tenclea collect 事件不会触发代码中的任何内容,所以我还不能测试它。未打印日志。
-
不带过滤器可以试试吗?
标签: javascript node.js discord discord.js