discord.js v13 TypeError:无法读取未定义的属性“createMessageCollector”

Posted

技术标签:

【中文标题】discord.js v13 TypeError:无法读取未定义的属性“createMessageCollector”【英文标题】:discord.js v13 TypeError: Cannot read property 'createMessageCollector' of undefined 【发布时间】:2021-11-23 16:46:17 【问题描述】:

自从我更新到 discord.js v13 后,我一直收到错误消息。谁能帮帮我?

错误:

TypeError: Cannot read property 'createMessageCollector' of undefined

代码:

        var TitleEmbed = new Discord.MessageEmbed()
            .setColor(Color.general)
            .setTitle(`$Mode Post Title`)
            .setDescription(`Please enter a title for your post, it should summarise your description in a few words. If selling, you should also include whether you're for hire, or selling assets.`);
        const TitleEmbedSent = await Message.author.send( embeds: [TitleEmbed] ).then(msg => msg.channel).catch(() => 
            return Message.channel.send(`Sorry $Message.author, but I couldn't direct Message you!`)
        );
        const Collector = TitleEmbedSent.channel.createMessageCollector( MessageFilter, max: 1, time: 300000 );

【问题讨论】:

【参考方案1】:

我会继续前进

var TitleEmbed = new Discord.MessageEmbed()
            .setColor(Color.general)
            .setTitle(`$Mode Post Title`)
            .setDescription(`Please enter a title for your post, it should summarise your description in a few words. If selling, you should also include whether you're for hire, or selling assets.`);
        try 
            Message.author.send( embeds: [TitleEmbed] ).then(msg => 
                 const collector = msg.channel.createMessageCollector( MessageFilter, max: 1, time: 300000 ));
            );
         catch (err) 
            return Message.channel.send(`Sorry $Message.author, but I couldn't direct Message you!`);
        

你的代码的问题是你用message.channel声明了变量TitleEmbedSent,这在这段代码中显然意味着DMChannel,这很好,但是当你去创建你的MessageCollector时,你会尝试通过做再次找到.channel

const Collector = TitleEmbedSent.channel.createMessageCollector( MessageFilter, max: 1, time: 300000 );

TitleEmbed 已经是一个频道,您无法从channel 中获取channel

【讨论】:

以上是关于discord.js v13 TypeError:无法读取未定义的属性“createMessageCollector”的主要内容,如果未能解决你的问题,请参考以下文章

Discord.js V13:如何编辑交互的消息对象?

如何使用 discord.js 调用 SubCommand 的选项? (v13)

Discord.js:错误:更新到 v13 后“找不到模块 'node:events'”

Ping 为负值(Discord.js v13)

Discord.js V13 欢迎消息

Discord Bot 不播放音频 discord.js v13