简体   繁体   中英

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!

Use method .deleteReply() :

async execute(interaction) {
  const replyMessage = await interaction.reply('message');
  setTimeout(() => interaction.deleteReply(), 10000);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM