【问题标题】:Using a Reaction Collector on a message the bot sent对机器人发送的消息使用反应收集器
【发布时间】:2021-06-12 22:42:35
【问题描述】:

在这个机器人上工作了一段时间,但我似乎被难住了。每次我运行它,它都会说

UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“createReactionCollector”

这是由
const collector = message.createReactionCollector(filter, { time: 15000 });
引起的 我不知道该怎么做。大多数其他示例要么已过时,要么出于特定目的而制作,因此很难将它们实现到我的代码中。非常感谢您提供的任何帮助!

if (command === 'ping') {
    const pingEmbed = new Discord.MessageEmbed()
        .setColor('#03cffc')
        .setTitle('Ping!')
        .setDescription(`${message.author.username} is playing a game! \n \n Playing With: \n ` + isPlaying);
    message.channel.send(pingEmbed)
        .then(sentEmbed => {
            sentEmbed.react("????")
        }).then( async message => {
            const filter = (reaction, user) => {
                return reaction.emoji.name === '????' && user.id === message.author.id;
            };

            const collector = message.createReactionCollector(filter, { time: 15000 });

            collector.on('collect', (reaction, user) => {
                console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
            });

            collector.on('end', collected => {
                console.log(`Collected ${collected.size} items`);
            });
        })}

【问题讨论】:

  • 是否在正确的范围内?是否定义了“消息”?
  • message 正在返回未定义
  • 是的,我明白了,它应该包含集合的消息就是它发送的消息。我需要帮助的是如何在机器人刚刚发送的消息上设置反应收集器
  • 如果message已经是你的全局发送消息对象的名称,不要再使用名称message,使用另一个名称例如msgm
  • 我刚试过,但是,错误仍然发生我需要的是一种在机器人刚刚发送的对象上创建反应收集器的方法,所以我不介意代码被更改,我我只是说我尝试过的。

标签: javascript discord.js


【解决方案1】:

您不需要使用两个then 方法。对于您的情况,只需一个就足够了。不必使用另一个then 方法并传入message,您只需将message 替换为sentEmbed

代码:

if (command === 'ping') {
    const pingEmbed = new Discord.MessageEmbed()
        .setColor('#03cffc')
        .setTitle('Ping!')
        .setDescription(`${message.author.username} is playing a game! \n \n Playing With: \n ` + isPlaying);
    message.channel.send(pingEmbed)
        .then(sentEmbed => {
            sentEmbed.react("?")
            const filter = (reaction, user) => {
                return reaction.emoji.name === '?' && user.id === message.author.id;
            };

            const collector = sentEmbed.createReactionCollector(filter, { time: 15000 });

            collector.on('collect', (reaction, user) => {
                console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
            });

            collector.on('end', collected => {
                console.log(`Collected ${collected.size} items`);
            });
        })
}

【讨论】:

    猜你喜欢
    • 2020-08-12
    • 2020-08-02
    • 2021-12-18
    • 1970-01-01
    • 2021-07-04
    • 2021-04-11
    • 2021-10-31
    • 2020-07-28
    • 2020-02-23
    相关资源
    最近更新 更多