【问题标题】:How to react to messages sent by a webhook?如何对 webhook 发送的消息做出反应?
【发布时间】:2020-07-17 18:35:27
【问题描述】:

我想为 webhook 发送的消息添加响应,但我不知道如何操作或如何获取此消息的 ID 以便能够对其做出响应。这是我的代码:

const webhookClient = new Discord.WebhookClient(config.webhookID, config.webhookToken);

    message.delete();

    const embed = new Discord.RichEmbed()
        .setColor('#00ffff')
        .setTitle(`Suggestion`)
        .setDescription(`${message.content}`)
        .setTimestamp()
        .setFooter(`User ID: ${message.author.id}`);

    webhookMessage = webhookClient.send('', {
        username: message.author.username,
        avatarURL: message.author.avatarURL,
        embeds: [embed]
    });
    webhookMessage.react('????').then(() => webhookMessage.react('????'));
    return;
}

【问题讨论】:

  • 你有什么错误吗?
  • 似乎没有定义webhookMessage
  • @Syntle 是的,我知道:TypeError: webhookMessage.react is not a function 但我不知道如何对此消息添加反应或获取其 ID。

标签: node.js discord discord.js


【解决方案1】:

您的解决方案应该是:

webhookMessage = await webhookClient.send('',
{ username: message.author.username,
 avatarURL: message.author.avatarURL,
 embeds: [embed] }); 
await webhookMessage.react('?');
await webhookMessage.react('?');

【讨论】:

  • 我仍然遇到同样的错误。您向我建议的代码仅更改添加了await。或者也许有办法获取 webhook 发送的消息的 ID?
  • webhookClient.send() 返回 Message 所以我不确定为什么这对你不起作用,你应该能够使用 webhookMessage.id 获取消息 ID
  • 毕竟,它对我不起作用。但是,我找到了另一种方式来回复此消息;我刚刚从频道中获取了最后一条消息并添加了一个反应。但是,为频道添加冷却时间很重要,因为同时有大量消息,机器人会错误地添加反应。
  • 错误添加反应怎么办?如果你的意思是它以错误的顺序添加它们,那么我当前的答案将解决这个问题,因为它不会与 ? 反应,直到它与 ? 反应
  • 不,它将? 添加到一条消息,? 添加到第二条消息,而对于其他消息,它不会添加任何反应。但是如果2秒左右会有1条消息就好了。
猜你喜欢
  • 1970-01-01
  • 2021-04-11
  • 2020-06-13
  • 1970-01-01
  • 2021-05-08
  • 2021-07-04
  • 2021-10-31
  • 2021-03-05
  • 2019-05-24
相关资源
最近更新 更多