【发布时间】:2022-11-17 04:25:27
【问题描述】:
我正在尝试做一个音乐测验,机器人播放一首歌并问“这首歌的名字是什么?”,然后给用户一个 30 秒的时间段,它可以输入歌曲名称,否则它会说没有人能及时得到正确答案。现在,当我尝试执行此命令并给出正确答案时,机器人只是忽略它并等待 30 秒用完并说没有人及时正确。
const filter = m => m.content.toLowerCase() === item.title.toLowerCase(); // the filter
interaction.reply({ content: "What is the name of this song?"})
const collector = interaction.channel.createMessageCollector({ filter, time: 30000 }); // creates a collector with the filter and 30 second time period
collector.on('collect', m => { // this is the event that gets triggered if it gets collected
console.log(`Collected ${m.content}`);
interaction.followUp(`${m.author} got the correct answer!`)
queue.skip()
});
collector.on('end', collected => { // this is the even that gets triggered when the time runs out
console.log(`Collected ${collected.size} items`);
interaction.followUp(`${collected.size} people got the right answer!`)
queue.skip()
});
item 对象只是一个 JSON 文件,其中包含当前歌曲的数据:艺术家、URL 和标题。因此,对于此示例,我们假设这是给定的信息:
{
"title": "Uptown Funk",
"url": "https://www.youtube.com/watch?v=OPf0YbXqDm0",
"singers": ["Mark Ronson", "Bruno Mars"]
},
然后即使用户说 uptown funk,也不会被接受。
【问题讨论】:
-
你觉得这个有什么作用?
m.content.includes(item.title.toLowerCase() === item.title.toLowerCase())。特别是这个:item.title.toLowerCase() === item.title.toLowerCase()
标签: javascript discord.js