1

I'm trying to code a warning system for a discord bot using Discord.JS and Sequelize. Saving the warns works, but fetching doesn't work.

async function warnGet() {
            let msgArgs = message.content.split(" ");
            var ReportID = Math.floor(1000 + Math.random() * 9000);
            let messageReason = msgArgs[2]
              ? message.content.substring(
                  msgArgs.slice(0, 3).join(" ").length + 1
                )
              : "No reason provided";
            (async () => {
              try {
                let userTag = member.user.tag;
                let warningYes = JSON.stringify(
                  await moderationLogging.findAll({
                    where: {
                      Member: userTag,
                    },
                  }),
                  { raw: true }
                );
                warningYes = JSON.parse(warningYes);
                const faqembed = new MessageEmbed()
                  .setColor("#ff9100")
                  .addField(
                    `Reason: ${warningYes.Reason}`,
                    `Report ID: ${warningYes.ReprtID}`
                  )
                  .setAuthor(
                    member.user.username,
                    member.user.displayAvatarURL({
                      format: "jpg",
                      dynamic: "true",
                    })
                  );
                warningYes.forEach((e) => {
                  faqembed.addField(
                    `Reason: ${warningYes.Reason}`,
                    `Report ID: ${warningYes.ReprtID}`
                  );
                });
                message.channel.send(faqembed);
              } catch (error) {
                message.channel.send(
                  `Aw maaaaan. I couldn't do the thing I needed to do. <@388813100964642816> should prob know about this. The technical stuff\` \`\`\`xl\n${clean(
                    error
                  )}\n\`\`\``
                );
                console.log(error);
              }
            })();
          }

this code when ran returns this This leads to the result.

I'm not sure why. Any help would be appreciated. These are the entries it's trying to get Image

1 Answer 1

1

Update! So, I actually solved it on my own! Instead of doing

               warningYes = JSON.parse(warningYes);
                const faqembed = new MessageEmbed()
                  .setColor("#ff9100")
                  .addField(
                    `Reason: ${warningYes.Reason}`,
                    `Report ID: ${warningYes.ReprtID}`
                  )

I did this

                const warning = JSON.parse(warningYes);
                const faqembed = new MessageEmbed()
                  .setColor("#ff9100")
                  .addField(
                    `Reason: ${warning[0].Reason}`,
                    `Report ID: ${warning[0].ReprtID}`
                  )
                  .setAuthor(
                    member.user.username,
                    member.user.displayAvatarURL({
                      format: "jpg",
                      dynamic: "true",
                    })
                  );

If you need to know, I added a [0] on the end of it. Turns out that was all I needed. It's fixed now, so yeah!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.