delete messages discord bot code example
Example 1: discordjs delete all messages in channel
// Bulk delete messages
channel.bulkDelete(5)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
Example 2: delete message discord.js
message.delete()
Example 3: discord delete message
"create a variable called id"
var id
"then inside your client message statement change id -> id = message.id"
client.on('message', message => {
id = message.id
});
"inside your command type message.fetch(id).then(msg => msg.delete());"
if (message.content === !test)
message.fetch(id).then(msg => msg.delete());
}});
Example 4: discord bot clear messages
switch(args[0]){
case 'clear':
if(!args[1]) return message.reply('Error please define second argument')
message.channel.bulkDelete(args[1]);
break;
}
Example 5: 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)