问题
I am doing a report system for a discord bot and I want the player to report a specific message by the id so that the moderators can decide if it is offensive or not. I am struggling to find a way to get the message's text from the given id. Is there a possible way of doing this?
回答1:
You can retrieve a message by id through
msg.channel.fetchMessage();
The documentation is here. If you want to be able to retrieve a message from any channel by id, you can loop through all channels and catch any errors.
回答2:
fetchMessage
is no longer present in Discord.js starting in version 12, but you can use the fetch
method of the MessageManager
class from the messages
property of the TextChannel
class.
msg.channel.messages.fetch("701574160211771462")
.then(message => console.log(message.content))
.catch(console.error);
来源:https://stackoverflow.com/questions/49442638/get-message-by-id-discord-js