【问题标题】:Discord.js - .then is not defined even though it's in a function?Discord.js - .then 即使在函数中也没有定义?
【发布时间】:2021-04-15 09:42:40
【问题描述】:

在搜索答案、编辑代码和尝试新方法大约 20 小时后。我已经放弃了,决定在这里问。

我完全厌倦了这段代码。 我要做的是: 1. 等待消息收到 2 个反应 2. 2 个反应后,将消息发布到单独的频道

编辑:在一些用户建议在我的 .then 之前删除我愚蠢地放置的 console.log 之后,此代码现在继续不等待对消息的反应,而是在不向指定频道发布消息的情况下完成整个过程 请多多包涵,我还在学习中。

代码如下:

  client.on('message', msg => {
    const filter = (reaction, user) => reaction.emoji.name === '703033480090484756' && user.id === message.author.id;
    msg.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
    .then(collected => {
    const starboard = new Discord.MessageEmbed()
    .setColor(0xFF0000)
    .setAuthor(`${msg.author.username}`, `${msg.author.avatarURL()}`)
    .setDescription(`${msg.author.content}`)
    
     client.channels.cache.get('714842643766444122').send(starboard)})
    .catch(err => console.log(err), ('Passed! Added to starboard.'));
    console.log('Added to Starboard!');

如果您需要更多详细信息,请询问。

【问题讨论】:

  • 您正在(试图)在您的 console.log 上致电 then

标签: discord discord.js


【解决方案1】:
client.on('message', async msg => {
    let rMessage = await msg.channel.send("Test Message");
    await rMessage.react('703033480090484756');
    const filter = (reaction, user) => reaction.emoji.name === '703033480090484756' && user.id === msg.author.id;
    rMessage.awaitReactions(filter, { max: 1, time: 30000, errors: ['time'] })
    .then(collected => {
    const starboard = new Discord.MessageEmbed()
    .setColor(0xFF0000)
    .setAuthor(`${msg.author.username}`, `${msg.author.displayAvatarURL()}`)
    //.setDescription(`${msg.author.content}`)
    
     client.channels.cache.get('714842643766444122').send(starboard)})
    .catch(err => console.log(err), ('Passed! Added to starboard.'));
    console.log('Added to Starboard!');

您在console.log('Woah! Passed the filter...') 上使用了.then

【讨论】:

  • 是的,另一位用户提到了这一点。我删除了它以在 .awaitreactions 上使用 .then。但是,Now It 将整个代码遍历到最终的 console.log 以显示完成,而无需实际等待消息上的反应
  • 编辑了我的答案。如果你现在写一条消息,它应该发送Test Message 并用表情符号做出反应。如果您点击此表情符号,您选择的频道中应该会出现一个嵌入内容。
猜你喜欢
  • 1970-01-01
  • 2020-03-25
  • 2018-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-24
  • 1970-01-01
  • 2019-12-13
相关资源
最近更新 更多