I have tried looking for how to delete a message by id and I get the id by getting the channel and going through the json object and take the last message id and want to delete it but when I run it just deletes the entire channel
This is what I have for the code
let x = client.channels.cache.get('830341462070919168')
let lastMessageID = x.lastMessageID;
client.channels.cache.get('830341462070919168').fetch(lastMessageID).then(msg => msg.delete());
client.channels.cache.get('830341462070919168').send('**UPDATE!!**\nList of Photo Shoots to be done\n```1. Nick\n2. Drew```');
And I saw on another form that I could try this
client.channels.cache.get('830341462070919168').fetch(lastMessageID).then(async msg => {
await client.channels.cache.get('830341462070919168').send("**UPDATE!!**\nList of Photo Shoots to be done\n```1. Nick\n2. Drew```");
if (msg) msg.delete();
});
And it does the same thing as what I have above
All I want it to do is just get the last message id and delete that message by the id and nothing else and then update with a new message that I will have loop through all the sign ups and then put that into a message
output: UPDATE!! Lise of Photo Shoots to be done
1. {name}
2. {name}
etc..
I fixed it all I needed to do was to put the id inside the delete function
Example:
client.channels.cache.get('830342527340773386').messages.delete(lastMessageID);
In your case, client.channels.cache.get('830341462070919168').fetch(lastMessageID)
would return the channel itself. So calling Channel.delete()
would delete the channel. So you can either do like what you have answered, or do client.channels.cache.get('830341462070919168').message.fetch(lastMessageID)
to get the message and then resolve the promise to delete the message. <MessageManager>#fetch()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.