discordjs delete message code example

Example 1: discord js delete message after time

message.reply('Invalid command')
  .then(msg => {
                msg.delete({ timeout: 20000 /*time unitl delete in milliseconds*/});
            })
  .catch(/*Your Error handling if the Message isn't returned, sent, etc.*/);

Example 2: delete message discord.js

message.delete()

Example 3: discord js clear message from id

//Updated to d.js v12 & fixed some bugs | 
// Input: [!clear @user <amount>] & [!clear <amount>] !Command name and prefix depend on your code!

		const user = message.mentions.users.first();

        let amount = !!parseInt(message.content.split(' ')[1]) ? parseInt(message.content.split(' ')[1]) : parseInt(message.content.split(' ')[2])
        amount = Math.floor(amount + 1);
        if (!amount) return message.reply('You need to specify an amount.');
        if (!amount && !user) return message.reply('You need to specify a user and an amount.');

        messages.channel.messages.fetch({
         limit: 100,
        }).then((messages) => {
         if (user) {
         const filterBy = user ? user.id : Client.user.id;
         messages = messages.filter(m => m.author.id === filterBy).array().slice(0, amount);
         } else {
            messages = amount;
         }
            message.channel.bulkDelete(messages).catch(error => console.log(error.stack));
        });

Example 4: discord bot remove message

import discord.ext

bot = commands.Bot(";")

@bot.event 
async def on_message(message):
    if message.content.upper().startswith(";SAY"):
        args = message.content.split(" ")
        await bot.send_message(message.channel, "%s" % (" ".join(args[1:])))
        await bot.delete_message(message)