javascript - 为什么我的交互收集器不收集?(discord.js)
问题描述
我是 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 => {
确实火了。这可能是因为我不是一个好的程序员。如果可以,请帮忙!
解决方案
您有一个MessageComponentCollector
内部事件处理程序interactionCreate
,在这种情况下,这可能不是您想要的。
这是正在发生的事情:
你点击按钮
您的
eventCreate
处理程序触发,检查它是否是被单击的按钮并启动 MessageComponentCollectorMessageComponentCollector
等待按钮单击,并且尚未触发,因为已经发生了一个(首先触发您的处理interactionCreate
程序的那个)每当您再次单击该按钮时,收集器就会触发,但
interactionCreate
处理程序也会触发,然后您返回#2
,启动另一个收集器
您可能想要的是在没有收集器的情况下处理您的按钮点击:
client.on('interactionCreate', interaction => {
if (!interaction.isButton()) return;
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);
}
});
推荐阅读
- android - android-4.3_r1的repo sync aosp,.repo目录大小达到70G
- java - 如何生成excel范围的PNG/JPG?
- vbscript - 关闭另一个进程打开的文件
- git - 多版本项目中的版本控制问题
- r - 概率输入 XGBOST R
- python - Mod_Wsgi 缺少符号
- python-3.x - 在其目录系统中读取 LIDC-IDRI 数据集?
- assembly - MOVNTSS 有多少性能损失?
- python - 在 Python 中调用 C 函数并返回 2 个值
- sql-server - 在 Azure SQL Server 上创建从本地 SQL Server 读取表的视图