- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
#Is there a way to keep the references of chats, messages and collectors on discord.js with database
26 messages · Page 1 of 1 (latest)
you could just temporary cache the message id in memory or in database and when it logs in, you fetch the message and initiate the collector
those ids are in different files, how could i do this ?
someone told me about partial events
sorry if my english is not correct, i'm still learning
and there is a easier way to initiate the collector? or i need to repeat all the code of the previous collector?
parameters:
admChannel.js --> modalInteraction, datas(contain titles and ids), channel (reference to the user chat);
admSatisfaction.js --> infos (object that receive: channel (the user channel); response (the message sent in the admChannel, so it can be eddited); modalInteraction; workers ( the attendents);
createModal.js --> datas ( the same data used above); interaction (the interaction on the select menu);
createUserChannel.js --> modalInteraction; datas (the same data above);
userSatisfaction.js --> infos (the same infos above)
admChannel send a message that have two buttons : 1_ register the name of who click; 2_ end the ticket and send a rating message to both chats, user, and adm;
admSatisfaction is the responsable to create the rating and embeds to the adms chat;
createModal, create and send the values to the files that need it ( createUserChannel.js; admChannel.js;
createUserChannel, send the initial message to the user chat with the modal information and set permissions to that chat;
initialMenu create a menu when the bot is ready, the menu have 4 options, each for a different type of modal;
userSatisfaction is the responsable to send the rating questions and delete the user chat 30s after the rating end
If you need the buttons to work after restarting the client its easier and more efficient to use the interactionCreate event. You could use the buttons customId to indicate the channel it’s in reference to.
Message Components: Component interactions - The Client#interactionCreate event
read more
You would use that event to reply to those buttons.
What does the rating interaction do besides close the channel?
You can share your code if you like
it send a embed with the ratings
ok
const {
EmbedBuilder,
} = require("discord.js");
const { createRatingMessage } = require("../utils/createRatingMessage");
const { buttonCollect } = require("../events/waitButtonCollect");
async function admSatisfaction(infos) {
let embedMessage = new EmbedBuilder({
title: `1_ Como você avalia o usuário ${infos.modal.user.globalName} no quesito educação?`,
}).setColor([255, 135, 0]);
const educationRatingMessage = await infos.admResponse.edit(createRatingMessage(embedMessage));
const educationRatingResult = await buttonCollect(educationRatingMessage);
embedMessage.addFields({
name: "Educação",
value: educationRatingResult.answer.customId,
inline: true,
});
embedMessage.setTitle("2_ Como você avalia a coesão do problema?");
const cohesionRatingMessage = await educationRatingMessage.edit(createRatingMessage(embedMessage));
const cohesionRatingResult = await buttonCollect(cohesionRatingMessage);
embedMessage.addFields({
name: "Coesão",
value: cohesionRatingResult.answer.customId,
inline: true,
});
embedMessage.setTitle("3_ Qual o seu nível de satisfação geral com o usuário?");
const overallRatingMessages = await cohesionRatingMessage.edit(createRatingMessage(embedMessage));
const overallRatingResult = await buttonCollect(overallRatingMessages);
embedMessage.addFields({
name: "Geral",
value: overallRatingResult.answer.customId,
inline: true,
});
embedMessage.setTitle(`Atendimento do usuário ${infos.modal.user.username} finalizado`);
embedMessage.setDescription(`Atendentes: ${infos.workers.length === 0 ? "Sem registro" : infos.workers.join(", ")}`);
await infos.admResponse.edit({embeds: [embedMessage], components: []});
};
module.exports = { admSatisfaction };
this is one send it to the admChannel
const { EmbedBuilder } = require("discord.js");
const { createRatingMessage } = require("../utils/createRatingMessage");
const { buttonCollect } = require("../events/waitButtonCollect");
const { serviceId } = require("../../config.json");
async function userSatisfaction(infos) {
let embedMessage = new EmbedBuilder({
title: `1_ Qual o seu nível de satisfação com o tempo de atendimento?`,
}).setColor([255, 135, 0]);
const timeRatingMessage = await infos.channel.send(createRatingMessage(embedMessage));
const timeRatingResult = await buttonCollect(timeRatingMessage);
embedMessage.addFields({
name: "Tempo",
value: timeRatingResult.answer.customId,
inline: true,
});
embedMessage.setTitle("2_ Qual o seu nível de satisfação com a resolução do problema?");
const solutionRatingMessages = await timeRatingMessage.edit(createRatingMessage(embedMessage));
const solutionRatingResult = await buttonCollect(solutionRatingMessages);
embedMessage.addFields({
name: "Solução",
value: solutionRatingResult.answer.customId,
inline: true,
});
embedMessage.setTitle("3_ Qual o seu nível de satisfação geral?");
const overallRatingMessages = await solutionRatingMessages.edit(createRatingMessage(embedMessage));
const overallRatingResult = await buttonCollect(overallRatingMessages);
embedMessage.addFields({
name: "Geral",
value: overallRatingResult.answer.customId,
inline: true,
});
embedMessage.setTitle("Resultado avaliação final:");
overallRatingMessages.edit({embeds: [embedMessage], components: []});
const time = 30;
const feedbackMessage = new EmbedBuilder({
title: "Muito obrigado pelo feedback",
description: `
Sempre que necessário utilize a sala <#${serviceId}> para relatar problemas.
Esse chat será deletado em: <t:${Math.floor(overallRatingResult.answer.createdTimestamp / 1000) + time}:R>
`,
}).setColor([255, 135, 0]);
await infos.channel.send({embeds: [feedbackMessage]});
try {
setTimeout(() => {
infos.channel.delete();
},time * 1000);
}catch(error) {
console.error(error);
};
};
module.exports = { userSatisfaction };
and this one send to the user channel
Do you send the buttons on the same message you are editing? It would be easier to call <interaction>.update() to edit the embed if so.
i did it like this because the adm chat will work like a record of the tickets, and if i send another in another message, the message will go to the bottom of the chat