admin管理员组

文章数量:1410737

I know the question exists but even though I looked into the other question and i used 'sendEmbed' instead of 'send' but nothing seems to work, if anyone can help with this error I'll be grateful :)

this is my code:

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = "Removed For Security";

const PREFIX = "!";

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

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

    switch (args[0]) {
        case 'ping':
            msg.channel.send("pong!")
            break;
        case 'clear':
            if (!args[1])
                return msg.reply('Error please define second argument');
            msg.channel.bulkDelete(args[1]);
            break;
        case 'embed': {
            const embed = new Discord.RichEmbed()
                .addField('Player Name', msg.author.username)
            msg.channel.send(embed)
            break;
        }
    }
})

bot.login(token);

and this is the error:

C:\Users\isam\Desktop\discord bot\index.js:24
            const embed = new Discord.RichEmbed()
                          ^

TypeError: Discord.RichEmbed is not a constructor
    at Client.bot.on (C:\Users\isam\Desktop\discord bot\index.js:24:27)
    at Client.emit (events.js:193:13)
    at MessageCreateAction.handle (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
    at WebSocketShard.onMessage (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\Users\isam\Desktop\discord bot\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:193:13)
    at Receiver.receiverOnMessage (C:\Users\isam\Desktop\discord bot\node_modules\ws\lib\websocket.js:800:20)

As you can see the error is in RichEmbed constructor, also my Discord.js version is '12.2.0', Any ideas?

I know the question exists but even though I looked into the other question and i used 'sendEmbed' instead of 'send' but nothing seems to work, if anyone can help with this error I'll be grateful :)

this is my code:

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = "Removed For Security";

const PREFIX = "!";

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

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

    switch (args[0]) {
        case 'ping':
            msg.channel.send("pong!")
            break;
        case 'clear':
            if (!args[1])
                return msg.reply('Error please define second argument');
            msg.channel.bulkDelete(args[1]);
            break;
        case 'embed': {
            const embed = new Discord.RichEmbed()
                .addField('Player Name', msg.author.username)
            msg.channel.send(embed)
            break;
        }
    }
})

bot.login(token);

and this is the error:

C:\Users\isam\Desktop\discord bot\index.js:24
            const embed = new Discord.RichEmbed()
                          ^

TypeError: Discord.RichEmbed is not a constructor
    at Client.bot.on (C:\Users\isam\Desktop\discord bot\index.js:24:27)
    at Client.emit (events.js:193:13)
    at MessageCreateAction.handle (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
    at WebSocketShard.onPacket (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
    at WebSocketShard.onMessage (C:\Users\isam\Desktop\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
    at WebSocket.onMessage (C:\Users\isam\Desktop\discord bot\node_modules\ws\lib\event-target.js:125:16)
    at WebSocket.emit (events.js:193:13)
    at Receiver.receiverOnMessage (C:\Users\isam\Desktop\discord bot\node_modules\ws\lib\websocket.js:800:20)

As you can see the error is in RichEmbed constructor, also my Discord.js version is '12.2.0', Any ideas?

Share Improve this question edited Jun 4, 2020 at 17:04 GottZ 4,9471 gold badge37 silver badges47 bronze badges asked Jun 4, 2020 at 16:42 SaboSukeSaboSuke 7921 gold badge9 silver badges27 bronze badges 4
  • You just sent your token to everyone. I would heavily remend you to generate a new one if you do not want your bot to be used by anyone else – Tenclea Commented Jun 4, 2020 at 16:48
  • doesn't really matter since I can regenerate it anytime. – SaboSuke Commented Jun 4, 2020 at 16:49
  • 1 Just wanted to be sure :) – Tenclea Commented Jun 4, 2020 at 16:51
  • 1 Yea I know, thanks for that :) – SaboSuke Commented Jun 4, 2020 at 16:52
Add a ment  | 

2 Answers 2

Reset to default 7

Discord.RichEmbed got removed in v12.

just use Discord.MessageEmbed instead.

it's essentially the same. just a new name.

new docs: https://discord.js/#/docs/main/v12/class/MessageEmbed

Discord.RichEmbed got removed in V12

try this :

const embed = new Discord.MessageEmbed()

//l'embed

msg.channel.send(embed)

本文标签: javascriptHow to fix RichEmbed DiscordjsStack Overflow