Home > Mobile >  When purging messages by user and term, the wrong embed is sent
When purging messages by user and term, the wrong embed is sent

Time:09-09

I've been working to create a Purge Command in JavaScript based off this The little nuisance of a message I'm referring to

Secondly, when I purge specifically by user and term, the wrong embed is sent and my bot will purge as normal. According to the source code, it (referring to my bot) should be sending the cleanPurge embed, but it instead sends the userPurge embed. Purging specifically by user works as intended, just with the annoying "thinking" message as an unwanted bonus.

Thirdly, when purging by term, I can only purge if I enact the command right after a message with the specified term. Here's an example (if you don't understand my wording).

// It is okay to purge during these situations

// cat in a hat
// cat in a hat
// cat in a hat

// /purge [amount: 3] {term: cat}

// The command will purge only if it is enacted right after the message with the specific term, however...


// The command won't purge during these situations

// cat in a hat
// cat in a hat
// cat in a hat
// SHITPOST

// /purge [amount: 3] {term: cat}

// The message "SHITPOST" is in-between the last message with the term "cat" and when I enact my command, 
// therefore, for some reason, I can't purge any messages with my specified keyword before the message "SHITPOST".

// I can purge messages with the term "cat" AFTER the message "SHITPOST" until another message gets in the way.

// If you have no idea what I mean, a link to my bot's demo is below.

Purging without specifics DOESN'T bring up the "{Bot} is thinking..." message and works as intended.

If you're confused, here's a link to a demo of my bot's bugs

Any questions, please feel free to ask me, and sorry if my wording is shit.

Source code for purge.js

const { EmbedBuilder, ApplicationCommandOptionType, PermissionsBitField } = require("discord.js");
const { Command } = require("reconlx");
const ms = require("ms");

module.exports = new Command({
    name: "purge",
    description: "Deletes a specified number of messages",
    userPermissions: PermissionsBitField.Flags.ManageMessages,
    options: [
        {
            name: "amount",
            description: "Number of messages to purge",
            type: ApplicationCommandOptionType.Integer,
            min_value: 1,
            max_value: 100,
            required: true,
        },
        {
            name: "user",
            description: "Purge this member's messages",
            type: ApplicationCommandOptionType.User,
            required: false,
        },
        {
            name: "term",
            description: "Purge messages with this specific term",
            type: ApplicationCommandOptionType.String,
            required: false,
        },
        {
            name: "reason",
            description: "Reason for purging",
            type: ApplicationCommandOptionType.String,
            required: false,
        },
    ],

    run: async ({ interaction }) => {
        const amount = interaction.options.getInteger("amount");
        const user = interaction.options.getUser("user");
        const term = interaction.options.getString("term");
        const reason = interaction.options.getString("reason") || "Unspecified";
        const channel = interaction.channel
        const messages = await interaction.channel.messages.fetch({ 
            limit: amount   1,
        });

        if (user) {
            const userMessages = messages.filter((m) => m.author.id === user.id);
            const purged = await interaction.channel.bulkDelete(userMessages, true);

            const userPurge = new EmbedBuilder()
                .setColor("#2F3136")
                .setTitle(`           
  • Related