'Discord.js timeout timer not working and delete right away
Im trying to send a embed then after 5 seconds ins gonna get deleted. I haved tried this.
client.on('messageCreate', async (message) => {
if (message.content === '&unlock') {
await message.channel
.permissionOverwrites.edit(message.guild.id, { SEND_MESSAGES: true })
message.channel.send({ embeds: [unlockembed] }).then(message => message.delete({setTimeout: 5000}))
}
})
But the timer not working and the message get deleted right away.
Solution 1:[1]
This code will work for you and employs the new method of delayed message.delete()
client.on('messageCreate', async (message) => {
if (message.content === '&unlock') {
const channel = message.channel;
channel.permissionOverwrites.edit(message.guild.id, { SEND_MESSAGES: true })
message.channel.send({
embeds: [unlockembed]
}).then(msg => {
setTimeout(() => {
msg.delete()
}, 5000);
})
}
})
Solution 2:[2]
Previous to v13 Messages had a timeout
option for .delete()
, however you now need to use a setTimeout()
function.
setTimeout(message.delete, 5000);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Gh0st |
Solution 2 | Elitezen |