如何使用fetchMessages()获取一定数量的消息,然后以某种方式发送它们? [英] How to use fetchMessages() to fetch a certain amount of messages then send them in a certain way?

查看:63
本文介绍了如何使用fetchMessages()获取一定数量的消息,然后以某种方式发送它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是从解决 fetchMessages()中的承诺中获取信息,然后能够遍历它给出的集合和 然后 能够发送某些邮件。

What I would like to do is to take information from resolving a promise from fetchMessages() and then being able to go through the collection it gives and then being able to send certain pieces.

例如,该机器人将列出10条类似的消息GalaxyDJx#2462:嗨,如果可能,先查找信息(例如用户名,鉴别符,消息内容),然后将每条信息设置为其自己的变量,例如 var uname var discrm var msgcnt

For example, the bot will list 10 messages looking like GalaxyDJx#2462: hi by, if possible, finding the information (e.g. username, discriminator, message content) and then having each piece of information set to its own variable such as var uname, var discrm, and var msgcnt.

下面是我从一条消息中获得的信息,我真正需要的只是该成员的用户名,鉴别符,并获取他们发送的消息内容。

The information I got from one message is below and all I really need is the member's username, discriminator, and get the message content that they sent.

'439129579567972353' => Message {
  channel: TextChannel {
    type: 'text',
    id: '411925734970490880',
    name: 'galaxys-bot-testing',
    position: 3,
    parentID: '394174705655087104',
    permissionOverwrites: [Object],
    topic: '',
    nsfw: false,
    lastMessageID: '439131920736059402',
    guild: [Object],
    messages: [Object],
    _typing: Map {},
    lastMessage: [Object]
  },
  id: '439129579567972353',
  type: 'DEFAULT',
  content: '<@436985225546039337> fetch',
  author: User {
    id: '311283024312532993',
    username: 'GalaxyDJx',
    discriminator: '2462',
    avatar: 'IgnoreThis',
    bot: false,
    lastMessageID: '439131920736059402',
    lastMessage: [Object]
  },
  member: GuildMember {
    guild: [Object],
    user: [Object],
    _roles: [Array],
    serverDeaf: false,
    serverMute: false,
    selfMute: undefined,
    selfDeaf: undefined,
    voiceSessionID: undefined,
    voiceChannelID: undefined,
    speaking: false,
    nickname: null,
    joinedTimestamp: 1518280794719,
    lastMessageID: '439131920736059402',
    lastMessage: [Object]
  },
  pinned: false,
  tts: false,
  nonce: undefined,
  system: false,
  embeds: [],
  attachments: Collection {},
  createdTimestamp: 1524767050402,
  editedTimestamp: null,
  reactions: Collection {},
  mentions: MessageMentions {
    everyone: false,
    users: [Object],
    roles: Collection {},
    _content: '<@436985225546039337> fetch',
    _client: [Object],
    _guild: [Object],
    _members: null,
    _channels: null
  },
  webhookID: null,
  hit: null,
  _edits: []
}

我通过使用此代码获得了此信息。

I got this information from using this code.

var promise1 = Promise.resolve(message.channel.fetchMessages({limit: 1}));

promise1.then(function(value) {
  console.log(value);
});


推荐答案

由于 TextChannel.fetchMessages() 返回一个Promise,您不需要使用 Promise.resolve(),存储返回的值和所有这些东西:您可以这样做:

Since TextChannel.fetchMessages() returns a Promise, you don't need to use Promise.resolve(), store the returned value and all that stuff: you can just do this:

message.channel.fetchMessages({limit: 1}).then(console.log);
//       this returns a Promise          |     Here you're using Promise.then()

这篇关于如何使用fetchMessages()获取一定数量的消息,然后以某种方式发送它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆