【问题标题】:Add reaction of custom emoji to a message将自定义表情符号的反应添加到消息中
【发布时间】:2018-07-23 08:42:18
【问题描述】:

我可以在我的代码中进行哪些调整以允许我使用自定义表情符号对消息做出反应?

我试过这个:

 let suggestions = message.guild.channels.find("name", "suggestions");
  if (message.channel === suggestions) {
    message.channel.send().then(newMessage => {
       newMessage.react('<:information :412438127148531723>')
   })
  }

但我收到错误:

emoji_id:值“412438127148531723>”不是雪花。

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    由于这是您在谷歌上搜索此问题时的唯一回复,即使它已经 1 岁了,我也会回答。

    emoji_id:值“412438127148531723>”不是雪花。

    去掉最后的 > 就可以了

    newMessage.react('<:information :412438127148531723')
    

    为我工作。如果有人在谷歌上搜索同样的问题,希望它会有所帮助

    【讨论】:

      【解决方案2】:

      编辑:我没有注意到您试图通过.send() 发送空消息,这样做会引发错误。检查@Blundering Philosopher 的答案。

      由于错误状态 emoji_id: Value "412438127148531723&gt;" is not snowflake.,这表明您试图通过 .react() 传递一些不是您拥有的雪花的东西:

       newMessage('<:information :412438127148531723>') //here
      

      作为docs 状态,Emojiidsnowflake 的一种类型。

      因此,您需要通过.react(); 传递Emojiid,因此只需将这行:newMessage.react('&lt;:information :412438127148531723&gt;') 替换为:newMessage.react('412438127148531723')

      所以你的代码应该看起来像这样:

       let suggestions = message.guild.channels.find("name", "suggestions");
        if (message.channel === suggestions) {
          message.channel.send('your message').then(newMessage => {
             newMessage.react('412438127148531723')
         })
        }
      

      另外,请记住,这仅在机器人本身可以访问表情符号时才有效,即 - 共享具有这些表情符号的服务器;与 Discord Nitro 的工作方式相同。

      【讨论】:

        【解决方案3】:

        首先,您不能使用不带任何字符串的.send() 或括号中的StringResolvable。尝试发送这样的基本字符串:

        message.channel.send('Test message!').then(...)
        

        其次,正如@newbie 所提到的,您不应该在表情符号 id 周围加上 '&lt;:information... :&gt;',只需这样做:

        // enter your emoji id inside the quotes
        newMessage.react('...');
        

        最后,您应该将.catch 语句添加到任何返回promise 的Discord 函数(如.send.react),如下所示:

        message.channel.send(...).then(...)
            .catch(console.error);
        
        // and later in your code...
        newMessage.react(...)
            .catch(console.error);
        

        所以要将所有代码放在一起,请执行以下操作:

        let suggestions = message.guild.channels.find("name", "suggestions");
        if (message.channel === suggestions) {
            // (send some text to channel)
            message.channel.send('Test message!').then(newMessage => {
                // (add your emoji id inside quotes -> probably '412438127148531723'
                newMessage.react('...')
                // (catch errors)
                .catch(console.error);
            })
            // (catch errors)
            .catch(console.error);
        }
        

        【讨论】:

          猜你喜欢
          • 2019-05-07
          • 1970-01-01
          • 1970-01-01
          • 2021-08-09
          • 2020-03-20
          • 2019-03-12
          • 2018-09-25
          • 2022-10-04
          • 2021-08-04
          相关资源
          最近更新 更多