【问题标题】:How to get a bot react to its own embed?如何让机器人对自己的嵌入做出反应?
【发布时间】:2021-02-23 21:53:09
【问题描述】:

我试图弄清楚机器人将如何对嵌入做出反应,更具体地说,它自己的。我已经到了让机器人显示嵌入的步骤(在用户编写命令!开始之后),但它不会与 ????表情符号。感谢所有帮助!

const Discord = require('discord.js');
const bot = new Discord.Client();
const fs = require("fs");
const guild = new Discord.Guild();
const token = 'redacted';
const p1 = 'Player 1';

const serve = new Discord.MessageEmbed()
    .setColor('#0099ff')
    .setTitle('Time to serve!')
    .setDescription(p1 + ' react below to take the serve')
    .setThumbnail('https://cdn.discordapp.com/emojis/764193096060764211.png?v=1');


bot.on('ready', () =>{
    console.log('This bot is online!');
})





bot.on('message', message =>{
    
    if(message.content === "!start"){
        message.channel.send(serve);
    
    }

    
    if (message.content === serve ){
        embedMessage.react("????");
        
    }
    
})  



bot.login(token);

【问题讨论】:

  • 我也尝试过解决这个问题并添加了这个: bot.on('embed', Discord.MessageEmbed => { if (embed.content === serve) { embed.react("?? ??") } }) 但是,'=>' 处有一条红色下划线,表示应使用逗号

标签: discord discord.js


【解决方案1】:

有一种非常简单的方法可以让机器人对自己的消息做出反应。

只需发送消息或嵌入消息,.then() 就会对它做出反应?。这里之所以需要.then(),是因为我们需要等待消息真正发送出去,否则可能会出错。

message.channel.send(serve).then(m => {
  m.react("?");
})

【讨论】:

  • 但是当我这样做时,嵌入会永远循环!
  • 好吧,您需要在此之前添加一些逻辑。你知道,检查作者是否是机器人,确保它只对某些消息做出反应。那种东西。
猜你喜欢
  • 2018-12-15
  • 1970-01-01
  • 2020-11-07
  • 1970-01-01
  • 1970-01-01
  • 2020-07-29
  • 2020-12-05
  • 2020-08-06
  • 1970-01-01
相关资源
最近更新 更多