Reputation: 27
Hi, I'm new here and I've tried to delete last sendded message by bot but I cant do it can u help me with this problem
I've tried this (but it doesn't work):
if (msg.author.bot) msg.delete()
and also this:
setTimeout(() => message.delete(), 3000);
my code:
module.exports = {
name: "resetuj",
description: "Resetuje konto gracza!",
async run(client, message) {
const args = message.content.trim().split(/ +/);
const Nadano = new MessageEmbed()
.setTitle("Nie posiadasz permisji do tej komendy!")
.setColor(0x0EC0E7)
.setTimestamp('')
.setThumbnail('https://cdn.discordapp.com/avatars/814587842071101530/2b018bbe88c48b277a50145a404cdaea.png?size=512')
.setDescription("**Komenda dla administracji! #🆘|𝗖𝗘𝗡𝗧𝗥𝗨𝗠-𝗣𝗢𝗠𝗢𝗖𝗬 **")
message.channel.send(Nadano);
setTimeout(() => message.delete(), 3000);
}
Upvotes: 0
Views: 429
Reputation: 420
Message.author.id
returns a snowflake that doesn't have the .delete()
method. You'll want to resolve the promise that message.channel.send()
returns and call setTimeout
inside of that callback function so you have access to the newly sent message object:
message.channel.send(Nadano)
.then(msg => {
setTimeout(() => msg.delete(), 3000)
})
Or as pointed out below, you can use await
instead if you're in an async
function:
const msg = await message.channel.send(Nadano);
setTimeout(() => msg.delete(), 3000);
Upvotes: 1