-2

我正在努力做到这一点,所以当我的机器人在特定渠道中获得反应时,它会查看它是否在特定反应上达到 10 个反应。然后它会删除反应的消息并将其发布到另一个特定的频道,并附加一条消息。

这是代码

doopliss.on('message', message => {
  if (message.channel.id === "587066921422290953") {
    setTimeout(function(){
      message.react(message.guild.emojis.get('587070377696690177'))
    }, 10)
    setTimeout(function(){
      message.react(message.guild.emojis.get('587071853609353256'))
    }, 50)
    setTimeout(function(){
      message.react(message.guild.emojis.get('587070377704816640'))
    }, 100)
  }
});
const message = require("discord.js");
const emoji = require("discord.js");
const reaction = require("discord.js");
doopliss.on('message', message => {
  if (message.channel.id === "587066921422290953") {
  let limit = 2; // number of thumbsdown reactions you need
  if (message.reaction.emoji.name == message.guild.emojis.get('587070377696690177') 
  && reaction.count >= limit) message.reaction.message.delete();
  let tcontent = message.reaction.message.content
  let accept = message.guild.channels.get('587097086256873483')

  accept.send(`${tcontent} \`\`\`This server suggestion has been accepted by the community! Great job! Now a staff member just needs to forward it to username.\`\`\``)
}})

无法弄清楚如何做到这一点。

预期结果:机器人查看帖子是否有 10 个反应,然后将其删除并将相同的消息带到不同的频道实际结果:发生错误Cannot read 'channel' property

4

1 回答 1

0

首先,我想说像这样的一些问题有你搜索的内容。

此外,discord 文档和指南提供了等待反应部分

还有一些其他问题涉及指南中使用的主题或功能,通过搜索,您甚至可以找到与您几乎相同的问题

但是,这是您想要执行的操作的完整示例。你可以在 Promise 中添加一个计时器,而不是仅仅等待。我没有使用反应收集器,因为promise会快一点,但是你也可以创建一个多收集器的管理系统,或者使用client.on('messageReactionAdd').

const Discord = require('discord.js');
const config = require('./config.json');


const channelSuggestion = '<channelID>';
const channelSend = '<channelID>';
const emojiReact = '<emojiID>';
const prefixSuggestion = '!';
const reactionMax = 11;

const client = new Discord.Client();
client.on('ready', () => {
  console.log('Starting!');
  client.user.setActivity(config.activity);
});

client.on('message', (msg) => {
  if ((msg.content[0] === prefixSuggestion) && (msg.channel.type === 'dm')){
    sendSuggestion(msg);
  }
});


function filter(reaction) {
  return reaction.emoji.id === emojiReact;
}

function moveSuggestion(msg) {
  client.channels.get(channelSend).send(msg.content)
    .then(() => msg.delete()).catch(err => console.log(error));
}

function sendSuggestion(msg){
  client.channels.get(channelSuggestion).send(msg.content.substr(1))
    .then((newMsg) => newMsg.react(emojiReact))
    .then((newMsgReaction) => 
      newMsgReaction.message
      .awaitReactions(filter, {max: reactionMax})//, time: 15000, errors: ['time']})
      .then(collected => {
        moveSuggestion(newMsgReaction.message);
      })
      // .catch(collected => {
      //   console.log(`After a minute, only ${collected.size} out of 10 reacted.`);
      // })
     );
}

client.login(config.token)
  .then(() => console.log("We're in!"))
  .catch((err) => console.log(err));

该机器人将收听以!.
然后bot会向特定频道发送消息,等待N人添加反应,然后将消息发送到另一个频道。

于 2019-06-09T08:21:51.840 回答