繁体   English   中英

无法在 discord.js v13 上发送空消息

[英]Cannot send an empty message on discord.js v13

好的,我下载了一个适用于 discord.js V12(discord-pagination)的旧插件,我希望它也适用于 V13,那我该怎么办?

当我尝试使用我的命令时,它说Cannot send an empty message ,问题出在下面的代码中。

const paginationEmbed = async (msg, pages, emojiList = ["⏪", "⏩"], timeout = 120000) => {
    if (!msg && !msg.channel) throw new Error("Channel is inaccessible.");
    if (!pages) throw new Error("Pages are not given.");
    if (emojiList.length !== 2) throw new Error("Need two emojis.");
    let page = 0;
    const curPage = await msg.channel.send(pages[page].setFooter(`Page ${page + 1} / ${pages.length}`));
    for (const emoji of emojiList) await curPage.react(emoji);
    const reactionCollector = curPage.createReactionCollector((reaction, user) => emojiList.includes(reaction.emoji.name) && !user.bot, { time: timeout });
    reactionCollector.on("collect", (reaction) => {
        reaction.users.remove(msg.author);
        switch (reaction.emoji.name) {
            case emojiList[0]:
                page = page > 0 ? --page : pages.length - 1;
                break;
            case emojiList[1]:
                page = page + 1 < pages.length ? ++page : 0;
                break;
            default:
                break;
        }
        curPage.edit(pages[page].setFooter(`Page ${page + 1} / ${pages.length}`));
    });
    reactionCollector.on("end", () => {
        if (!curPage.deleted) {
            curPage.reactions.removeAll();
        }
    });
    return curPage;
};
module.exports = paginationEmbed;

从您的代码猜测,我认为问题在于发送嵌入。

message.channel.send(embed) // deprecated
message.channel.send({embeds: [embed] }) // V13 version

因此,对于您,您必须更改一行:

// change this
const curPage = await msg.channel.send(pages[page].setFooter(`Page ${page + 1} / ${pages.length}`));
// to this
const curPage = await msg.channel.send({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });

curPage.edit

// change this
curPage.edit(pages[page].setFooter(`Page ${page + 1} / ${pages.length}`));
// to this
curPage.edit({ embeds: [pages[page].setFooter(`Page ${page + 1} / ${pages.length}`)] });

您也可能想阅读指南,了解如何从 V12 更新到 V13

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM