-4

I have the id of the message, the id of the guild, and the channel id i just want to know how to delete a message with just those three things

I have looked everywhere and haven't found something that works

1 Answers1

2

"I have looked everywhere and haven't found something that works."

Did you not look at the djs docs? I found the answer to your question on the docs in seconds. Not to mention, dozens of other StackOverflow questions found in one google search, such as this one. Regardless, I'll show you how to do it.

All you really need is the ID of the message and channel. And the client instance. You don't even need the guild ID. Here's the code:

const channelId = "insert channel id here";
const messageId = "insert message id here";

client.channels.fetch(channelId).then(channel => {
    channel.messages.delete(messageId);
});

That code is the easiest way to delete a message by ID, assuming you only have access to the client. If you have access to a channel instance already (e.g. message.channel), the only code you need to do is the code within the .then() shown above.

Cannicide
  • 4,360
  • 3
  • 22
  • 42
  • channels are already cached on startup – Azer Apr 17 '22 at 08:33
  • @Azer indeed the channels are cached on startup, but afaik the channel cache is not necessarily always accurate and up-to-date at any given time that the bot is online. If the message is being deleted by ID on bot startup, sure, you could just use the cache. If not, fetching is more reliable. Since deleting a message is asynchronous anyways, fetching the channel shouldn't be much of a problem. – Cannicide Apr 17 '22 at 17:35