我得到了这个乱码,如果时间用完后没有人得到正确答案,它就结束。但是收集器不知何故没有结束。这个代码工作得很好,但是我希望收集器在给定的有限时间内结束。
密码是这样的:
const listword = ['array', 'of', 'words'];
var word = listword[Math.floor(Math.random() * listword.length)].toLowerCase();
var jumbled = word
.split('')
.sort(function () {
return 0.5 - Math.random();
})
.join('');
interaction.followUp({ content: `The word is ${word}`, ephemeral: true });
await interaction.channel.send(`Guess the word \`${jumbled}\`!`);
const filter = (response) => listword.includes(response.content.trim());
const collector = interaction.channel.createMessageCollector(filter, {
time: 15000, //this doesn't work somehow
});
collector.on('collect', (response) => {
if (response.author.bot) return;
var guessword = response.content.trim();
if (guessword.toLowerCase() === word) {
response.react('✅');
response.reply({
content: `${response.author} guessed it right! The word was \`${word}\`.`,
allowedMentions: { users: [], roles: [], repliedUser: false },
});
collector.stop();
} else {
if (response.author.bot) return;
response.react('❌');
}
});
collector.on('end', (collected) => {
if (!collected.size) {
interaction.channel.send(
'Time is up! Nobody was able to guess the word' + `\`${word}\`.`
);
}
});
我不知道为什么收集器不结束,除非这个词被猜对了。我需要做什么来修复它?
1条答案
按热度按时间46qrfjad1#
在discord.js v13中,所有与收集器相关的类和方法(
.create*()
和.await*()
)都采用单个对象参数。这意味着createMessageCollector
接受单个参数,即options
对象。(以前,第一个参数是filter
,第二个参数是options
)。当您提供
filter
作为第一个参数时,带有time
键的对象将被忽略,只需传递一个带有filter
和time
的对象,它将正常工作:类似的回答:https://stackoverflow.com/a/70455975/6126373