I’m making a ticketinfo command that get’s information about a ticket that’s in my database.
I’m trying to catch the information from the database and put in into my embed. The embed is being send to the user that runs that command.
It seems to not work. Why isnt it working?
My Code:
const Discord = require("discord.js") const colours = require("../colours.json"); const botconfig = require("../botconfig.json"); const mongo = require('../mongo') const transcriptSchema = require('../models/transcript-schema') module.exports.run = async(bot, message, args) => { message.delete(); const guildId = botconfig.guildid let ticketId = args.slice(0).join(" "); if (!ticketId) return message.reply("Bitte gebe eine Ticket-ID an!") const results = await transcriptSchema.findOne({ guildId: guildId, ticketId: ticketId, }) // try { for (const transcript of results.transcripts) { const { guildId, ticketId, userId, channelId, channelName, timestamp } = transcript let checkembed = new Discord.MessageEmbed() .setAuthor(`${colours.mainname} - Ticket Informationen`) .setColor(colours.maincolour) .addField(`Ticket-ID:`, ``${ticketId}``, true) .addField(`Ticket-Name:`, ``${channelName}``, true) .addField(`Server-ID:`, ``${guildId}``, true) .addField(`Channel-ID:`, ``${channelId}``, true) .addField(`Erstellt von:`, `<@${userId}>`, true) .addField(`Geschlossen am:`, `${new Date(timestamp).toLocaleDateString()}`, true) .addField(`Geschlossen von:`, `${user}`, true) .setThumbnail(`https://media.discordapp.net/attachments/827294233014173726/829738374557990983/NR_CEO.png?width=683&height=683`) message.author.send(checkembed) } // } catch (err) { // console.log("ID not found") // } } module.exports.config = { name: "ticketinfo", aliases: [] }
Error:
(node:20620) UnhandledPromiseRejectionWarning: TypeError: results.transcripts is not iterable at Object.module.exports.run (C:UserseFhiiDesktopNateR eSports[development][nateresports]commandsticketinfo.js:21:38) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:20620) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:20620) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Advertisement
Answer
It seems, that result.transcripts
either does not exist, or is not an array or an iterator. You should check, what the findOne
function actually returns.