【问题标题】:How do I fix RichEmbed?如何修复 RichEmbed?
【发布时间】:2020-06-26 06:29:11
【问题描述】:

我正在尝试在不和谐中打印 get embed 消息,但发生了这种情况:

TypeError: Discord.RichEmbed 不是构造函数

这是我的代码:

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'mytokenhere';
const prefix = '!';

bot.on('ready', () => {
    console.log('This bot is online!');
});

bot.on('message', message => {
    let args = message.content.substring(prefix.length).split(" ");

    switch(args[0]) {
        case 'pomoc':
            message.channel.send('.')
            break;
        case 'cc':
            if(!args[1]) return message.reply('Podaj 2 argument! (liczbe wiadomosci do skasowania)')
            message.channel.bulkDelete(args[1]); 
            break;
        case 'embed':
            var embed = new Discord.RichEmbed()
                .setAuthor(message.author.username)
                .setDescription("Usuario rikolino.")
                .setColor("#3535353")
                .addField("Usuario", '${message.author.username}#${message.author.discriminator}')
                .addField("ID", message.author.id)
                .addField("Creación", message.author.createdAt);

            message.channel.send({embed});
            break;
    }
});

bot.login(token);

我尝试了很多其他的解决方案,但结果总是一样,我真的不知道问题出在哪里。

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

Discord.js

discord.js 已从 new Discord.RichEmbed() 更新 new Discord.MessageEmbed()

const embed = new Discord.MessageEmbed()
    .setAuthor(message.author.username)
    .setDescription("Usuario rikolino.")
    .setColor("#3535353")
    .addField("Usuario", '${message.author.username}#${message.author.discriminator}')
    .addField("ID", message.author.id)
    .addField("Creación", message.author.createdAt);

message.channel.send(embed);

【讨论】:

    【解决方案2】:

    就像 Edric 说的,改用MessageEmbed

    var embed = new Discord.MessageEmbed()
        .setAuthor(message.author.username)
        .setDescription("Usuario rikolino.")
        .setColor("#3535353")
        .addField("Usuario", '${message.author.username}#${message.author.discriminator}')
        .addField("ID", message.author.id)
        .addField("Creación", message.author.createdAt);
    
    message.channel.send(embed);
    

    【讨论】:

      【解决方案3】:

      看起来它在 v12 中已重命名为 MessageEmbed

      如果您不想替换所有现有代码,可以使用以下解决方法:

      const { MessageEmbed: RichEmbed } = require("discord.js");
      
      let embed = new RichEmbed().setTitle("Works the same");
      

      【讨论】:

        【解决方案4】:

        无论你在哪里使用RichEmbed(); 改用MessageEmbed();

        【讨论】:

          猜你喜欢
          • 2020-09-23
          • 2020-05-18
          • 2020-07-24
          • 1970-01-01
          • 2020-10-14
          • 2020-05-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多