我目前正在尝试制作一个discord机器人,该机器人在使用某个命令!job时通过嵌入到频道来显示“订单”。参数也是嵌入中的字段。然后,用户必须键入“接受”以接受所述工作。然后,这会删除它发布的第一个嵌入内容,然后发布一个新的声明“订单已关闭”,以便其他任何人都无法再“接受”该订单。
问题:重新启动漫游器后,第一个嵌入始终可以正常工作;但是,“订单已关闭”嵌入帖子记录了所有先前的嵌入。例如。如果第一个作业的状态为“ x”,则嵌入仅按预期的顺序输出该顺序。但是,如果第二个作业被记录为“ y”,则两者都将被输出并堆叠。在第三阶上,它输出所有3个记录的等。
使用!job之后:
输入“接受”后,要接受作业:
放置并接受第二个作业后,将输出两个订单:
相关代码:
client.on("ready", () => {
console.log(`Starting up. Running version ${version}`)
});
function isCommand(command, message) {
var command = command.toLowerCase(); //If a user types a command with uppercase either lowercase
var content = message.content.toLowerCase()
return content.startsWith(prefix + command); //Checking if the message has a prefix first.
};
//isNotCommand function (needed
client.on('message', (message) => {
if (isCommand('job', message)) {
const args = message.content.slice(prefix.length).trim().split(/ +/g);
// Checking if they have perms
if (message.member.roles.cache.find(r => r.name === "Owner")) {
const boostEmbed = new discord.MessageEmbed()
.setColor('GREEN')
.setDescription("A job has just been placed. Details are below.")
.setAuthor('? Job Placed!')
.addField("Rank", args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5], true)
.addField("Queue", args[6], true)
.addField("Console", args[7], true)
.addField("Payout", args[8], true)
const closedEmbed = new discord.MessageEmbed()
.setColor('RED')
.setDescription("~~A job has just been placed. Details are below.~~")
.setAuthor('? Job Closed!')
.addField("Rank", "~~" + args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5] + "~~", true)
.addField("Queue", "~~" + args[6] + "~~", true)
.addField("Console", "~~" + args[7] + "~~", true)
.addField("Payout", "~~" + args[8] + "~~", true)
const messagingEmbed = new discord.MessageEmbed()
.setColor('GREEN')
.setDescription("You have accepted the job. Details are below.")
.setAuthor('? Job Accepted!')
.addField("Rank", args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5], true)
.addField("Payout", args[8], true)
.addField("Username", args[9], true)
.addField("Password", args[10], true)
if (args[1] === undefined) {
message.author.send("!job <Rank> <Queue | Single / Duo> <Console> <Payout> <Username> <Password>")
.then(function(message) {
setTimeout(function() {
message.delete();
}, 10000);
})
} else { // Main
message.guild.channels.cache.get(channelidrequest).send(boostEmbed)
message.guild.channels.cache.get(channelidrequest).send("React if you want to take the job!")
.then(function(message) {
message.react("✅")
})
const filter = m => m.content.includes('accept');
const collector = message.channel.createMessageCollector(filter, {
time: 172800000
});
collector.on('end', collected => {
message.guild.channels.cache.get(channelidrequest).bulkDelete(1);
const msg = message.guild.channels.cache.get(channelidrequest).fetchMessages({
limit: 1
})
msg.edit(closedEmbed);
})
console.log(collector)
collector.on('collect', message => {
if (message.content == "accept") {
message.channel.send("Hello");
}
const user = message.author
if (user.id === "722188709612748830") {
console.log("No Bots");
} else {
message.guild.channels.cache.get(channelidrequest).bulkDelete(2);
message.guild.channels.cache.get(channelidrequest).send(closedEmbed);
const joblogEmbed = new discord.MessageEmbed()
.setColor('YELLOW')
.setDescription("A job has just been logged. Details are below.")
.setAuthor('? Job Logged!')
.addField("Rank", args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5], true)
.addField("Queue", args[6], true)
.addField("Console", args[7], true)
.addField("Payout", args[8], true)
.addField("Username", args[9], true)
.addField("Password", args[10], true)
.addField("Booster", "<@" + user.id + ">", true)
message.guild.channels.cache.get(channelidlog).send(joblogEmbed)
user.send(messagingEmbed);
}
长话短说,当我只希望它显示与所下订单相关的“已关闭订单”嵌入内容时,将输出堆栈彼此叠加。抱歉,如果有任何困惑,这是我的第一篇文章。
答案 0 :(得分:-1)
我也发生了同样的现象。 但是,当我重新启动服务器时,它已经治愈。