【问题标题】:MessageEmbed description must be a stringMessageEmbed 描述必须是字符串
【发布时间】:2022-01-15 18:34:07
【问题描述】:

这是我的代码,我收到此错误: RangeError [EMBED_DESCRIPTION]: MessageEmbed description must be a string 有人可以帮我吗?我从v12更新到v13,现在出现这个错误,还没有找到解决办法。

const { MessageEmbed } = require('discord.js');
const Command = require('../../Structures/Command');

module.exports = class extends Command {

    constructor(...args) {
        super(...args, {
            aliases: ['halp'],
            description: 'Displays all the commands in the bot',
            category: 'Utilities',
            usage: '[command]'
        });
    }

    async run(message, [command]) {
        const embed = new MessageEmbed()
            .setColor('BLUE')
            .setAuthor(`${message.guild.name} Help Menu`, message.guild.iconURL({ dynamic: true }))
            .setThumbnail(this.client.user.displayAvatarURL())
            .setFooter(`Requested by ${message.author.username}`, message.author.displayAvatarURL({ dynamic: true }))
            .setTimestamp();

        if (command) {
            const cmd = this.client.commands.get(command) || this.client.commands.get(this.client.aliases.get(command));

            if (!cmd) return message.channel.send(`Invalid Command named. \`${command}\``);

            embed.setAuthor(`${this.client.utils.capitalise(cmd.name)} Command Help`, this.client.user.displayAvatarURL());
            embed.setDescription([
                `**❯ Aliases:** ${cmd.aliases.length ? cmd.aliases.map(alias => `\`${alias}\``).join(' ') : 'No Aliases'}`,
                `**❯ Description:** ${cmd.description}`,
                `**❯ Category:** ${cmd.category}`,
                `**❯ Usage:** ${cmd.usage}`
            ]);

            return message.channel.send(embed);
        } else {
            embed.setDescription([
                `These are the available commands for ${message.guild.name}`,
                `The bot's prefix is: ${this.client.prefix}`,
                `Command Parameters: \`<>\` is strict & \`[]\` is optional`
            ]);
            let categories;
            if (!this.client.owners.includes(message.author.id)) {
                categories = this.client.utils.removeDuplicates(this.client.commands.filter(cmd => cmd.category !== 'Owner').map(cmd => cmd.category));
            } else {
                categories = this.client.utils.removeDuplicates(this.client.commands.map(cmd => cmd.category));
            }

            for (const category of categories) {
                embed.addField(`**${this.client.utils.capitalise(category)}**`, this.client.commands.filter(cmd =>
                    cmd.category === category).map(cmd => `\`${cmd.name}\``).join(' '));
            }
            return message.channel.send(embed);
        }
    }

};

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    由于您将 discord.js 更新到 v13,&lt;MessageEmbed&gt;.setDescription 不再接受数组,您需要输入一个字符串或使用 &lt;Array&gt;.join,如下所示:

    embed.setDescription([
      `These are the available commands for ${message.guild.name}`,
      `The bot's prefix is: ${this.client.prefix}`,
      `Command Parameters: \`<>\` is strict & \`[]\` is optional`
    ].join('\n'));
    

    【讨论】:

      【解决方案2】:

      Discord.js 需要一个字符串,但你给它一个数组。 我会从 setDescriptions 中删除数组括号 [ ] 和逗号

      【讨论】:

        猜你喜欢
        • 2021-11-23
        • 2021-12-03
        • 2022-01-16
        • 2022-07-15
        • 2021-12-04
        • 1970-01-01
        • 2019-03-08
        • 1970-01-01
        • 2019-10-15
        相关资源
        最近更新 更多