当我运行一个命令时,它只是飞过消息,而是转到链接,它不应该是那样的,它应该是一个答案,然后去,回答,然后去等等。我修正了很多方法,但它仍然通过了一些问题,证明如下。
代码:
const {Client,Message,MessageEmbed} = require('discord.js')
/**
*
* @param {Client} bot
* @param {Message} message
*/
module.exports.run = async(bot, message) => {
let guild = bot.guilds.cache.get(`851186051598123008`)
let channels = guild.channels.cache.get(`866029925424824350`)
const filter = m => m.author.id === message.author.id
const intro = new MessageEmbed()
.setTitle("Bug Report | Introduction")
.setColor("GREEN")
.setDescription("Hello, I think you have seen a bug lately! Want to report it? Say `next` in order to continue with this prompt!")
.setFooter("Automatically cancelled in 2 minutes. | Say `cancel` to cancel the prompt.")
const cancelEmbed = new MessageEmbed()
.setTitle("Bug Report | Cancelled")
.setColor('RED')
.setDescription("Thank you for trying to report a bug! If you think this is a mistake, please run `<prefix>reportbug` or contact the CS team.")
const collector1 = message.channel.createMessageCollector(filter, {
max: "1",
maxMatches: '1',
time: 120000,
errors:['time']
})
const collector2 = message.channel.createMessageCollector(filter, {
max: "1",
maxMatches: '1',
time: 120000,
errors:['time']
})
const collector3 = message.channel.createMessageCollector(filter, {
max: '1',
maxMatches: '1',
time: 120000,
errors:['time']
})
const collector4 = message.channel.createMessageCollector(filter, {
max: '1',
maxMatches: '1',
time: 1000*60*5,
errors:['time']
})
const collector5 = message.channel.createMessageCollector(filter, {
max: '1',
maxMatches: '1',
time: 1000*60*2,
errors:['time']
})
message.channel.send(intro)
collector1.on('collect', msg => {
if(msg.content.toLowerCase() === "cancel"){
return message.channel.send(cancelEmbed)
}
if(msg.content.toLowerCase() === "next"){
const commandEmbed = new MessageEmbed()
.setTitle("Bug Report | Command Title")
.setDescription("What is the command name? This will give us the specific command.")
.setColor("YELLOW")
.setFooter("Automatically cancelled in 2 minutes. | Say `cancel` to cancel the prompt.")
message.channel.send(commandEmbed)
collector2.on('collect', m => {
if(m.content.toLowerCase() === "cancel"){
return message.channel.send(cancelEmbed)
}
if(m.content){
const descriptionEmbed = new MessageEmbed()
.setFooter("Automatically cancelled in 2 minutes. | Say `cancel` to cancel the prompt.")
.setDescription("What is the bug, as in what happened to reproduce?")
.setTitle("Bug Report | Bug Reproduction")
.setColor('YELLOW')
message.channel.send(descriptionEmbed)
collector3.on('collect', ms => {
if(ms.content.toLowerCase() === "cancel"){
return message.channel.send(cancelEmbed)
}
if(ms.content){
const evidence = new MessageEmbed()
.setFooter("Automatically cancelled in 5 minutes. | Say `cancel` to cancel the prompt.")
.setDescription("Is there any evidence? We only support gyzayo & discord atm! If you don't have any, put 'n/a'!")
.setTitle("Bug Report | Evidence")
.setColor('YELLOW')
message.channel.send(evidence)
collector4.on('collect', mm => {
if(mm.content.toLowerCase() === "cancel"){
return message.channel.send(cancelEmbed)
}
if(mm.content.startsWith('https://cdn.discordapp.com/attachments/' || 'https://gyazo.com/')){
const confirmEmbed = new MessageEmbed()
.setFooter("Automatically cancelled in 2 minutes. | Say `cancel` to cancel the prompt.")
.setDescription("Are you sure that you are going to post this? Option are `yes` or `no`")
.setTitle("Bug Report | Confirmation")
.setColor("YELLOW")
message.channel.send(confirmEmbed)
collector5.on('collect', me => {
if(me.content.toLowerCase() === "cancel"){
return message.channel.send(cancelEmbed)
}
if(me.content.toLowerCase() === "no"){
cancelEmbed.setDescription("Thank you for trying to report a bug! | You have denied to post it!")
return message.channel.send(cancelEmbed)
}
if(me.content.toLowerCase() === "yes"){
const infoEmbed = new MessageEmbed()
.setTitle("Bug Information")
.setColor('BLUE')
.addFields(
{
name: 'Guild Name:',
value: `${message.guild.name} (${message.guild.id})`,
inline: false
},
{
name: 'User: ',
value: `${message.author.tag} (${message.guild.id})`,
inline: false
},
{
name: 'Command Name: ',
value: m.content,
inline: false
},
{
name: 'Bug Description: ',
value: ms.content,
inline: false
},
{
name: 'Bug Proof/Evidence: ',
value: mm.content,
inline: false
}
)
channels.send(infoEmbed)
message.channel.send(`Thank you for submitting a bug report! A developer of ours will review and fix this current bug! You may join the support server by using the following command: \`<prefix>support\`!`)
}
if(!['yes','no','cancel'].includes(me.content)){
cancelEmbed.setDescription(`Thank you for trying to report a bug! | Please include a choice: ['yes','no','cancel'], and please run the prompt again.`)
return message.channel.send(cancelEmbed)
}
// Thank you for trying to report a bug!
})
}
if(mm.content.toLowerCase() === "n/a"){
const confirmEmbed = new MessageEmbed()
.setFooter("Automatically cancelled in 2 minutes. | Say `cancel` to cancel the prompt.")
.setDescription("Are you sure that you are going to post this? Option are `yes` or `no`")
.setTitle("Bug Report | Confirmation")
.setColor("YELLOW")
message.channel.send(confirmEmbed)
collector5.on('collect', me => {
if(me.content.toLowerCase() === "cancel"){
return message.channel.send(cancelEmbed)
}
if(me.content.toLowerCase() === "no"){
cancelEmbed.setDescription("Thank you for trying to report a bug! | You have denied to post it!")
return message.channel.send(cancelEmbed)
}
if(me.content.toLowerCase() === "yes"){
const infoEmbed = new MessageEmbed()
.setTitle("Bug Information")
.setColor('BLUE')
.addFields(
{
name: 'Guild Name:',
value: `${message.guild.name} (${message.guild.id})`,
inline: false
},
{
name: 'User: ',
value: `${message.author.tag} (${message.guild.id})`,
inline: false
},
{
name: 'Command Name: ',
value: m.content,
inline: false
},
{
name: 'Bug Description: ',
value: ms.content,
inline: false
},
{
name: 'Bug Proof/Evidence: ',
value: "N/A",
inline: false
}
)
channels.send(infoEmbed)
message.channel.send(`Thank you for submitting a bug report! A developer of ours will review and fix this current bug! You may join the support server by using the following command: \`<prefix>support\`!`)
}
if(!['yes','no','cancel'].includes(me.content)){
cancelEmbed.setDescription(`Thank you for trying to report a bug! | Please include a choice: ['yes','no','cancel'], and please run the prompt again.`)
return message.channel.send(cancelEmbed)
}
// Thank you for trying to report a bug!
})
}
if(!(mm.content.startsWith('https://cdn.discordapp.com/attachments/' && 'https://gyazo.com/') && ['n/a','cancel'].includes(mm.content))){
cancelEmbed.setDescription("Thank you for trying to report a bug! | Please include a choice: ['n/a','cancel'] or you used a unwhitelisted links of ours!")
}
})
}
})
}
})
}
if(!['next','cancel'].includes(msg.content)){
cancelEmbed.setDescription("Thank you for trying to report a bug! | Invalid option, choose: ['next','cancel'] and run the prompt again!")
message.channel.send(cancelEmbed)
}
})
collector1.on('end', collect => {
if(!collect.size) {
return message.reply(`You didn't reply on time!`)
}
})
collector2.on('end', collect2 => {
if(collect2.size === 0) {
return message.reply(`You didn't reply on time!`)
}
})
collector3.on('end', collect3 => {
if(collect3.size === 0){
return message.reply(`You didn't reply on time!`)
}
})
collector4.on('end', collect4 => {
if(collect4.size === 0){
return message.reply('You didn\'t reply on time!')
}
})
collector5.on('end', collect5 => {
if(collect5.size === 0) {
return message.reply(`You didn't reply on time.`)
}
})
}
module.exports.config = {
name: "bugreport",
aliases: ['reportbug']
}
如果有人能帮忙,那就太好了! <3
答案 0 :(得分:1)
您的代码同时创建所有收集器,这使得它们也同时触发,因为它们具有相同的 filter
函数。您应该这样做,以便它只在 收集来自前一个收集器的消息之后创建下一个收集器,如下所示:
await message.channel.send(intro);
const collector1 = message.channel.createMessageCollector(filter, {
max: "1",
maxMatches: '1',
time: 120000,
errors:['time']
});
collector1.on('collect', msg => {
(...)
const collector2 = message.channel.createMessageCollector(filter, {
max: "1",
maxMatches: '1',
time: 120000,
errors:['time']
});
collector2.on('collect', msg => {
const collector3 = (...);
}
collector2.on('end', collect => {
if(!collect.size) {
return message.reply(`You didn't reply on time!`)
}
});
}
collector1.on('end', collect => {
if(!collect.size) {
return message.reply(`You didn't reply on time!`)
}
});
顺便说一句,如果您改用 awaitMessages(),这可能会更简单。