为反应角色存储消息 ID

时间:2021-02-16 02:41:40

标签: javascript node.js discord discord.js

我一直在尝试存储反应角色消息,因此如果机器人离线,我不必重新运行命令,或者我可以在将来编辑它们。

我找到了一个存储第一条消息的教程,但不知道要添加/更改什么来存储所有其他反应消息(我总共有 6 个)。

我当前运行的代码是

const addReactions = (message, reactions) => {
  message.react(reactions[0])
  reactions.shift()
  if (reactions.length > 0) {
    setTimeout(() => addReactions(message, reactions), 750)
  }
}

module.exports = async (client, id, text, reactions = []) => {
  const channel = await client.channels.fetch(id)

  channel.messages.fetch().then((messages) => {
    if (messages.size === 0) {
      // Send a new message
      channel.send(text).then((message) => {
        addReactions(message, reactions)
      })
    } else {
      // Edit the existing message
      for (const message of messages) {
        message[1].edit(text)
        addReactions(message[1], reactions)
      }
    }
  })
}

我有 6 个不同的反应角色命令链接到此代码,并且正在考虑更改行

if (messages.size === 0) {

If (message.id !== ['id1', 'id2', 'id3','id4', 'id5', '1d6']) {

但我不确定这是否会达到我想要的效果?

对此的任何帮助将不胜感激。

0 个答案:

没有答案