Get Message By ID: Discord.js

守給你的承諾、 提交于 2020-06-08 17:00:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!