升级discord.js v13后createMessageCollector属性未定义报错如何解决
问题原因及修复方案
报错根本原因
- 代码存在属性重复调用问题:发送embed的Promise正常回调分支已经返回了
msg.channel(频道对象),后续调用时又额外拼接了.channel,相当于调用channel.channel,该属性不存在所以返回undefined。 - 存在逻辑漏洞:catch分支中返回的是
Message.channel.send()的执行结果,该结果是发送的报错提示消息对象,和正常分支返回的频道对象类型不统一,后续调用也会出现兼容问题。 - 不符合discord.js v13适配要求:
createMessageCollector的配置参数中,过滤器需要显式指定filter字段传入,不能直接将过滤器变量作为属性传递。
修复后代码
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.`); // 统一返回频道对象,正常分支返回DM频道,catch分支返回当前公屏频道 const TitleEmbedChannel = await Message.author.send({ embeds: [TitleEmbed] }) .then(msg => msg.channel) .catch(async () => { await Message.channel.send(`Sorry ${Message.author}, but I couldn't direct Message you!`) return Message.channel }); // 直接在频道对象上调用collector,显式指定filter字段 const Collector = TitleEmbedChannel.createMessageCollector({ filter: MessageFilter, max: 1, time: 300000 });
内容的提问来源于stack exchange,提问作者DbkboxiMoldoxjZfmebo
相关产品推荐
相关产品推荐

