如何使用fetchMessages()来获取一定量的信息,然后以某种方式给他们?(How to us

2019-10-30 02:40发布

我想这样做的是从解决从一个承诺采取信息fetchMessages()然后能够通过它给人的集合, 然后才能发送某些部分。

例如,机器人将列出10条消息看上去像GalaxyDJx#2462: hi通过,如果可能的话,找到的信息(例如用户名,鉴别器,消息内容),然后具有每条信息设置为它自己的变量如var unamevar discrmvar msgcnt

我从一个消息得到的信息是下面和我真正需要的是会员的用户名,鉴别,并得到他们发送的消息内容。

'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: []
}

我从使用此代码此信息。

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

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

Answer 1:

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

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


文章来源: How to use fetchMessages() to fetch a certain amount of messages then send them in a certain way?