Reputation:
I am trying to make my discord bot delete its message 2 seconds after is has been sent.
My current code for the message:
interaction.reply("You have removed $" + amount + " from @" + user.username + ". New balance: $" + receiverNewBalance + ".")
.then(msg => {
setTimeout(() => msg.delete(), 20000);
})
.catch(
interaction.channel.send("Error! [message could not be deleted]")
);
However when running it gives me this error:
TypeError: msg.delete is not a function
I don't understand why this does not work as it has worked for my older bots from the past. If discord js was updated and now it's different what is the new code I would need.
Upvotes: 0
Views: 1375
Reputation: 9041
CommandInteraction#reply()
in v13 returns undefined
, and ChatInputCommandInteraction#reply()
in v14 returns an InteractionResponse
. They both however return a Message
object if the fetchReply
option is set to a truthy value. You however don't need this, because you can simply use .deleteReply()
(v13 docs) on the interaction
.then(() =>
setTimeout(
() => interaction.deleteReply(),
2_000 // not sure if you wanted 2000 (2s) or 20000 (20s)
)
)
Upvotes: 1