我为Discord.js v12机器人发出了宣布命令。
运行命令时会发生什么:
这是我的代码:
// title
message.channel.send("What would be the title ?");
const titlecollector = new Discord.MessageCollector(
message.channel,
(m) => m.author.id === message.author.id,
{ time: 60000 }
);
// description
message.channel.send("What would be the description ?");
const descCollector = new Discord.MessageCollector(
message.channel,
(m) => m.author.id === message.author.id,
{ time: 180000 }
);
// ping
message.channel.send("Would i ping everyone, here or none ?");
const pingCollector = new Discord.MessageCollector(
message.channel,
(m) => m.author.id === message.author.id,
{ time: 60000 }
);
// channel
message.channel.send("Wich channel should i send it to ?");
const channelCollector = new Discord.MessageCollector(
message.channel,
(m) => m.author.id === message.author.id,
{ time: 60000 }
);
// color
message.channel.send("What color should i use ?");
const colourCollector = new Discord.MessageCollector(
message.channel,
(m) => m.author.id === message.author.id,
{ time: 180000 }
);
// THE ANNONCEMENT
const announcementEmbed = new Discord.MessageEmbed()
.setTitle(collector)
.setDescription(descriptionCollector)
.setFooter(`Sent by ${message.member.user.tag}`);
const channel = Client.channels.cache.find(
(channel) => channel.name === channelCollector
);
if (pingCollector == "everyone") {
channel.send("@everyone");
} else if (pingCollector == "here") {
channel.send("@here");
}
channel.send(announcementEmbed);
我希望它等待响应,然后将其存储。我的代码有什么问题?
答案 0 :(得分:0)
您需要等待消息,而不是使用消息收集器。
//title
message.channel.send("Enter a title").then(() => {
const filter = m => m.author.id == message.author.id //this ensures that it's waiting messages from the person who sent the message
message.channel.awaitMessages(filter, {time: 60000, max: 1, errors: ['time']) //the time variable is the amount of milliseconds it should wait for, change this accordingly
.then(async messages => {
let title = messages.first().content
//description
message.channel.send("Enter a description!").then(() => {
message.channel.awaitMessages(filter, {time: 60000, max: 1, errors: ['time'])
.then(async messages2 => {
let description = messages2.first().content
}).catch(() => {
message.channel.send("You didn't enter anything!")
})
})
}).catch(() => {
message.channel.send("You didn't enter anything!")
})
})
依此类推...