Reputation: 11
i have a problem with my discord bot.
i have a function with questions, and i have a restart function but i don't know how to stop function and run again.
async function restart(channel) {
builderquestions(channel)
}
async function builderquestions(channel) {
const intrebarea = await channel.send({ embed: { color, title: title[0], description: description[0], footer: { text: rescloseed } } })
await intrebarea.react('♻️')
await intrebarea.react('❌')
const collector = intrebarea.createReactionCollector((reaction, user) => message.guild.members.cache.find((member) => member.id === user.id), { dispose: true });
collector.on("collect", async (reaction, user) => {
switch (reaction.emoji.name) {
case "♻️": {
reaction.users.remove(user.id);
await restart(channel);
break;
}
case "❌": {
reaction.users.remove(user.id);
closeticket(channel)
break;
}
}
})
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer2", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: title[1], description: description[1], footer: { text: rescloseed } } })
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer3", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: title[2], description: description[2], footer: { text: rescloseed } } })
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer4", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: title[3], description: description[3], footer: { text: rescloseed } } })
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer5", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: title[4], description: description[4], footer: { text: rescloseed } } })
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer6", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: title[5], description: description[5], footer: { text: rescloseed } } })
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer7", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: title[6], description: description[6], footer: { text: rescloseed } } })
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer8", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: title[7], description: description[7], footer: { text: rescloseed } } })
const filter = m => m.author.id === message.author.id;
channel.awaitMessages(filter, { max: 1, time, errors: ["time"] })
.then(async (collected) => {
const msg = collected.first();
map.set("answer9", msg.content)
if (msg) {
msg.delete();
intrebarea.edit({ embed: { color, title: "Commission Info", description: `**Ticket: <#${channel.id}>**\n**Role**: Builder\n\n**${title[0]}**\n${map.get("answer2")}\n**${title[1]}?**\n${map.get("answer3")}\n**${title[2]}**\n${map.get("answer4")}\n**${title[3]}**\n${map.get("answer5")}\n**${title[4]}**\n${map.get("answer6")}\n**${title[5]}**\n${map.get("answer7")}\n**${title[6]}**\n${map.get("answer8")}\n**${title[7]}**\n${map.get("answer9")}`, footer: { text: copyright } } })
const question = await channel.send({
embed: { color: "266DFF", title: "Please react with:", description: "✔️ to complete,♻️ to restart, or ❌ to exit", footer: { text: copyright } }
})
await question.react('✔️');
await question.react('♻️')
await question.react('❌');
const collector = question.createReactionCollector((reaction, user) => message.guild.members.cache.find((member) => member.id === user.id), { dispose: true });
collector.on("collect", async (reaction, user) => {
switch (reaction.emoji.name) {
case "❌": {
reaction.users.remove(user.id);
closeticket(channel)
break;
}
case "♻️": {
reaction.users.remove(user.id);
restart(channel)
break;
}
case "✔️": {
}
}
})
}
})
}
})
}
})
}
})
}
})
}
})
}
})
}
if (!msg) return message.reply("Operation canceled");
})
}
When I start restart function, my builderquestion function continue to work.I tried many things, but they didn't work.
If you have an idea, you can leave it.
Upvotes: 1
Views: 202
Reputation: 72
I didn't read the code at all, but to stop and restart the function insert this where You need:
return builderquestions();
The keyword return
makes the function stop, and builderquestions()
makes the function run again.
This should work.
Upvotes: 1