如何获取特定用户在特定频道上的所有消息

How do I get all the messages of a specific user on a specific channel

下面是聊天(频道名称是 newchannel - 当玩家执行命令时创建频道):

Bot: Hello, what's your name.
User: BaconSoda479
Bot: When is your birthday
User: 21/06/1999
Bot: Do you like this bot?
User: Yes

现在,我想将所有用户的消息发送到一个特定的频道,这样我就可以创建一个在频道中显示时看起来像这样的嵌入:

User: BaconSode479
Birthday: 21/06/1999
Opinion: Yes

我预测嵌入会是这样的:

`User: ${client.channels.get(newchannel.id).second.message}`
`Birthday: ${client.channels.get(newchannel.id).fourth.message}`
`Opinion: ${client.channels.get(newchannel.id).sixth.message}`

我正在尝试创建一个变量,其中的字符串是聊天中特定消息的 ${message.content}

要获取频道的消息,您可以使用 TextChannel.fetchMessages(). You can then filter those messages to keep only the ones sent by the user with Collection.filter()。之后,您可以使用前三个消息来构建您的嵌入。
这是一个例子:

// Assuming newchannel is the TextChannel where the messages are, and that the only user allowed to write in the channel is the one you want to get the data from.

newchannel.fetchMessages().then(collected => {
  const filtered = collected.filter(msg => !msg.author.bot);
  const messages = filtered.first(3);

  const text = `
    User: ${messages[0].content}
    Birthday: ${messages[1].content}
    Opinion: ${messages[2].content}
    `;
});

您可以使用 awaitMessages() 实时准确地记录结果,而不是稍后再获取消息。无论如何,你应该在问题链中这样做。

创建新频道后将代码放在下面 (channel)。机器人会问第一个问题并等待用户的回答。然后它将被添加到嵌入中并询问下一个问题。最后一个问题后,将发送嵌入并删除频道。

const questions = [
  { title: 'Name', message: 'Hello! What\'s your name?' },  // You can change these
  { title: 'Birthday', message: 'When\'s your birthday?' }, // messages or add any
  { title: 'Opinion', message: 'Do you like this bot?' }    // questions as you please.
];

const filter = m => m.author.id === message.author.id;

var embed = new Discord.RichEmbed()
  .setColor('#ffffff')                                             // Feel free to edit this
  .setAuthor(message.author.tag, message.author.displayAvatarURL); // embed; only an example.

for (const question of questions) {    
  await channel.send(question.message);
  await channel.awaitMessages(filter, { max: 1, time: 60000 })
    .then(collected => {
      const response = collected.first() ? collected.first().content : '*No Answer*';
      embed.addField(question.title, response.length <= 1024 ? response : `${response.slice(0, 1021)}...`)
    });
}

const responsesTo = message.guild.channels.get('ID'); // Insert the ID to your channel here.
if (!responsesTo) return;

await responsesTo.send(embed); // Could make a webhook for efficiency instead.
await channel.delete();

console.log('Done.');

注意:代码需要在异步函数中。