В команде, которую я разместил ниже, у меня бот реагирует двумя смайликами на сообщение, отправленное на определенный канал. Но по какой-то причине, когда я указываю сообщение как msg, оно говорит, что оно не определено, какая-либо помощь? для сообщения, он просто отреагировал на исходное сообщение, которое я отправил, чтобы запустить команду.
Спасибо, Blu.
Код:
const Discord = require("discord.js");
let TicketChannelID = "729912166337216575";
let GuildID = "710634001513185371";
const talkedRecen = new Set();
module.exports.run = async (bot, message, args) => {
let avatar = message.author.avatarURL({
size: 2048
});
const filter = m => m.author.id === message.author.id;
let description = "";
let price = "";
const emojis = ["715383579059945512", "715383579059683349"];
if (talkedRecen.has(message.author.id)) {
message.reply(
"please wait till your two hours are up before you type this again."
);
} else {
let Prompt1 = new Discord.MessageEmbed()
.setTitle("Description")
.setDescription(
"Please specify a description for the asset you are selling below."
)
.setColor("#8c52ff")
.setTimestamp();
let Prompt2 = new Discord.MessageEmbed()
.setTitle("Price")
.setDescription(
"Please specify the price for the asset you are selling below."
)
.setColor("#8c52ff")
.setTimestamp();
message.channel.send("Redirected prompt to your DMs. If you didn't receive a DM from me, check your privacy settings and try again.");
message.author.send(Prompt1).then(p1 => {
let Description = new Discord.MessageCollector(p1.channel, filter, {
max: 1,
time: 60000
});
Description.on("collect", async newMS => {
let collectedMessage = newMS.content.toLowerCase();
if (collectedMessage.length >= 2048) {
collectedMessage.reply(
"The description you set for your asset is too long. Please try running the command again."
);
Description.stop();
return;
}
Description.stop();
description = collectedMessage;
p1.channel
.send(Prompt2)
.then(p2 => {
let Price = new Discord.MessageCollector(p2.channel, filter, {
max: 1,
time: 1200000
});
Price.on("collect", collectedMessage => {
if (collectedMessage.length >= 2048) {
collectedMessage.reply(
"The price you set for your asset is too long. Please try running the command again."
);
Price.stop();
return;
}
Price.stop();
price = collectedMessage.content;
let Prompt3 = new Discord.MessageEmbed()
.setTitle("Do you wish to send this for review?")
.setAuthor(message.author.tag, avatar)
.setColor("#8c52ff")
.addField("Description", description)
.addField("Price", price)
.addField("Contact", `<:discord:715391744090308700> - <@${message.author.id}>`)
.setFooter("Please respond with yes or no.")
.setTimestamp();
message.author.send(Prompt3).then(ex => {
let confirmationListener = new Discord.MessageCollector(
ex.channel,
filter, {
max: 1,
timer: 100000
}
);
confirmationListener.on("collect", collectedMessage => {
confirmationListener.stop();
let Message1 = collectedMessage.content.toLowerCase();
if (Message1 === "yes") {
let sellingembed = new Discord.MessageEmbed()
.setAuthor(message.author.tag, avatar)
.setColor("#8c52ff")
.addField("Description", description)
.addField("Price", price)
.addField("Contact", `<:discord:715391744090308700> - <@${message.author.id}>`)
.setTimestamp();
bot.guilds.cache
.get(GuildID)
.channels.cache.get(TicketChannelID)
.send(sellingembed)
.then(succ => {
collectedMessage.reply(
"Sent selling message for review."
);
msg.react(emojis[0]);
msg.react(emojis[1]);
const filter = (reaction, user) => emojis.includes(reaction.emoji.id) && user.id != bot.user.id;
const options = {
errors: ["time"],
time: 86400000,
max: 1
};
msg.awaitReactions(filter, options)
.then(collected => {
const first = collected.first();
if (emojis.indexOf(first.emoji.id) === 0) {
msg.delete();
let certainChannel = bot.channels.cache.get("715758259713212448");
certainChannel.send(sellingembed);
collectedMessage.reply("your selling message has been approved.");
} else {
msg.delete();
collectedMessage.reply("your selling message has been declined.");
}
})
.catch(err => {
console.log(err)
});
})
.catch(err => {
collectedMessage.reply("Error:\n" + err);
});
}
});
confirmationListener.on("end", (col, res) => {
if (!col.size && res == "time") {
return ex.reply(
"Timed out, try to repond within the given time."
);
}
});
});
});
Price.on("end", (col, res) => {
if (!col && res == "time") {
return message.reply(
"Timed out, try to respond within the given time."
);
}
});
})
.catch(err => {
p1.reply("Error: " + err);
});
Description.on("end", (col, res) => {
if (!col.size && res == "time") {
return p1.reply("Timed out, try to respond within the given time.");
}
});
});
});
talkedRecen.add(message.author.id);
setTimeout(() => {
talkedRecen.delete(message.author.id);
}, 7200000);
}
};
module.exports.help = {
name: "selling"
};