【问题标题】:Discord.js async not recording answersDiscord.js 异步不记录答案
【发布时间】:2021-02-25 07:02:25
【问题描述】:

我有以下代码

const schduele3 = new Discord.MessageEmbed()
        .setTitle('What time will should people start joining?')
        .setColor('BLUE')
        .setDescription('Send your message within 15 seconds! Make sure to include a time zone!')
message.channel.send(schduele3)
const msgs3 = await message.channel.awaitMessages(filter1, {max:1, time:15000})
const time = msgs3.content

它说我输入的东西是未定义的,有什么提示吗?

【问题讨论】:

    标签: javascript discord.js async.js


    【解决方案1】:

    Channel#awaitMessages 在满足条件后返回所有收集到的消息的集合(也就是选项中需要收集的最大消息量 - 在您的情况下是一个)。从这个逻辑来看,这个集合没有content 属性,只有它里面的消息对象有。如果你想要第一条收集到的消息,你应该使用.first()

    最终代码

    const schduele3 = new Discord.MessageEmbed()
            .setTitle('What time will should people start joining?')
            .setColor('BLUE')
            .setDescription('Send your message within 15 seconds! Make sure to include a time zone!')
    message.channel.send(schduele3)
    const msgs3 = await message.channel.awaitMessages(filter1, {
      max: 1, 
      time: 15000
    })
    const time = msgs3.first().content
    

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 1970-01-01
      • 2013-06-05
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      相关资源
      最近更新 更多