How do I delete an interaction reply in discord.js v13?


I’m trying to delete the bot’s reply to the user’s purge command.

module.exports = {
    data: new SlashCommandBuilder()
        .setName("purge") // Command name
        .setDescription("Deletes a set number of messages") // Command description
        .addNumberOption((option) => // Adds an argument
            option 
                .setName("number") // Argument name
                .setDescription("Sets the number of messages to delete") // Argument description
                .setRequired(true), // Argument requirement
        ),
    async execute(interaction) {
        if (interaction.member.permissions.has("MANAGE_MESSAGES") && interaction.guild.me.permissions.has("MANAGE_MESSAGES")) {
            await interaction.channel.bulkDelete(interaction.options.getNumber("number"));
            await interaction.reply(`Deleted ${interaction.options.getNumber("number")} message(s) successfully.`);
            setTimeout(() => interaction.message.delete(), 1000);
        } else if (interaction.member.permissions.has("MANAGE_MESSAGES") === false) {
            interaction.reply("You do not have the **Manage Messages** permission. Please ask a moderator to give you this permission.")
        } else {
            interaction.reply("I have not been given the relevant permissions to do this. Please contact a moderator and ask them to give me the **Manage Messages** permission.")
        }
    }
}

All the solutions I have tried all throw a " is not a function" or "Cannot read the property of undefined". Could anyone help with this? Thanks!

Source: JavaSript – Stack Overflow

November 26, 2021
Category : News
Tags: discord.js | javascript | node.js

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.