nyx/command/Utilities/suggest.js

91 lines
2.7 KiB
JavaScript

const { MessageEmbed } = require("discord.js");
module.exports = {
name: "suggest",
description: "Make a suggestion of the bot",
category: "Utilities",
type: "CHAT_INPUT",
run: async (client, interaction, args) => {
const questions = [
"Describe the suggestion",
// "question 2"
];
let collectCounter = 0;
let endCounter = 0;
const filter = m => m.author.id === interaction.user.id;
interaction.followUp("Check your dm.");
const appStart = await interaction.user.send({
embeds: [
new MessageEmbed()
.setAuthor(
interaction.user.username,
interaction.user.displayAvatarURL()
)
.setDescription(questions[collectCounter++])
.setFooter(`Made by ${client.author}`, client.user.displayAvatarURL())
.setTimestamp(),
],
});
const channel = appStart.channel;
const collector = channel.createMessageCollector({ filter });
collector.on("collect", () => {
if (collectCounter < questions.length) {
channel.send({
embeds: [
new MessageEmbed()
.setAuthor(
interaction.user.username,
interaction.user.displayAvatarURL()
)
.setDescription(questions[collectCounter++])
.setFooter(
`Made by ${client.author}`,
client.user.displayAvatarURL()
)
.setTimestamp(),
],
});
} else {
channel.send({
embeds: [
new MessageEmbed()
.setTitle("SUCCESS!")
.setDescription(
"You have sent a suggestion.\nPlease wait for us to review it"
)
.setColor("GREEN")
.setFooter(
`Made by ${client.author}`,
client.user.displayAvatarURL()
)
.setTimestamp(),
],
});
collector.stop("fulfilled");
}
});
const appsChannel = client.channels.cache.get(client.config.Config);
collector.on("end", (collected, reason) => {
if (reason === "fulfilled") {
const mapedResponses = collected
.map(msg => {
return `${questions[endCounter++]}**\n->** ${msg.content}`;
})
.join("\n\n");
appsChannel.send({
embeds: [
new MessageEmbed()
.setAuthor(
interaction.user.tag,
interaction.user.displayAvatarURL({ dynamic: true })
)
.setTitle("New Suggestion")
.setDescription(mapedResponses)
.setColor("ORANGE")
.setTimestamp(),
],
});
}
});
},
};