Reputation: 47
Purpose: I'm trying to make my bot check for reactions from a specific message.
I've read this post: Get Message By ID: Discord.js But it didn't help at all.
I've searched the internet to see how can I use .fetchMessage
properly. But unfortunately didn't find any results.
This is my code:
client.channels.get('CHANNEL ID').fetchMessage('MESSAGE ID').then(async msg => { *CODE HERE* });
This is the error i get:
TypeError: client.channels.get is not a function
I do realise that client.channels.get is not a function
and I should use this in a function but I don't know how to.
Discord.js version: 12.0.2
Node.js verison: 12.13
Upvotes: 4
Views: 3477
Reputation: 11
In v12 it has changed and uses managers and added this command to my bot and fixed it.
let channelMessage = client.channels.cache.get(channel_id) // Grab the channel
channelMessage.messages.fetch(message_id).then(messageFeteched => messageFeteched.delete({timeout: 5000})); // Delete the message after 5 seconds
Upvotes: 1
Reputation: 2675
That answer was for v11, in v12 it has changed to:
client.channels.cache.get(chid).messages.cache.fetch(mesid)
However, it's important to note that client.channels.cache may contain non-text channels, if you are retrieving an ID that you know to be a TextChannel type, you will be fine but if the ID is being retrieved programmatically you need to check to ensure it is an instanceof TextChannel.
Upvotes: 4