Reputation: 11
I'm trying to make a command for my discord bot that sends embeds in different channels(using the id) and deletes the message that was sent before. I've googled a lot and I still can't find a working solution on how to delete messages in a specific channel using the channel ID. I only need 1 message to be deleted if that's easier but I don't know.
This is my code:
client.channels.cache.get('channelid').messages.fetch().then(message => message.delete())
client.channels.cache.get('channelid').send({ embeds: [FAQEmbed] }); // sends FAQ Embed
I replaced the id with channelid
in case of anything. The embed works and it sends, but the message before doesn't get deleted.
Upvotes: 1
Views: 662
Reputation: 102
Yes your code correct, but if you want to delete the message when bot replied.
use message.channel.id
and message.id
to return message and channel id
example:
client.channels.cache.get(message.channel.id).messages.fetch(message.id).then(message => message.delete())
hope this help you, but you need to defined the client
as well
Upvotes: 1