如何修复RichEmbed Discord.js [英] How to fix RichEmbed Discord.js

查看:25
本文介绍了如何修复RichEmbed Discord.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题存在,但是即使我调查了另一个问题并且我使用了"sendEmbed"而不是"send",但似乎没有任何效果,如果有人可以帮助解决这个错误,我将不胜感激:)

这是我的代码:

  const Discord = require('discord.js');const bot = new Discord.Client();const token =安全性已移除";const PREFIX =!";bot.on('ready',()=> {console.log(启动在线");})bot.on('message',(msg)=> {让args = msg.content.substring(PREFIX.length).split(");开关(args [0]){案例"ping":msg.channel.send("pong!")休息;情况清楚":如果(!args [1])返回msg.reply('错误,请定义第二个参数');msg.channel.bulkDelete(args [1]);休息;案例嵌入":{const embed =新的Discord.RichEmbed().addField('玩家名称',msg.author.username)msg.channel.send(嵌入)休息;}}})bot.login(令牌); 

这是错误:

  C:\ Users \ isam \ Desktop \ discord bot \ index.js:24const embed =新的Discord.RichEmbed()^TypeError:Discord.RichEmbed不是构造函数在Client.bot.on(C:\ Users \ isam \ Desktop \ discord bot \ index.js:24:27)在Client.emit(events.js:193:13)在MessageCreateAction.handle(C:\ Users \ isam \ Desktop \ discord bot \ node_modules \ discord.js \ src \ client \ actions \ MessageCreate.js:31:14)在Object.module.exports [作为MESSAGE_CREATE]处(C:\ Users \ isam \ Desktop \ discord bot \ node_modules \ discord.js \ src \ client \ websocket \ handlers \ MESSAGE_CREATE.js:4:32)在WebSocketManager.handlePacket(C:\ Users \ isam \ Desktop \ discord bot \ node_modules \ discord.js \ src \ client \ websocket \ WebSocketManager.js:386:31)在WebSocketShard.onPacket上(C:\ Users \ isam \ Desktop \ discord bot \ node_modules \ discord.js \ src \ client \ websocket \ WebSocketShard.js:436:22)在WebSocketShard.onMessage(C:\ Users \ isam \ Desktop \ discord bot \ node_modules \ discord.js \ src \ client \ websocket \ WebSocketShard.js:293:10)在WebSocket.onMessage(C:\ Users \ isam \ Desktop \ discord bot \ node_modules \ ws \ lib \ event-target.js:125:16)在WebSocket.emit(events.js:193:13)在Receiver.receiverOnMessage(C:\ Users \ isam \ Desktop \ discord bot \ node_modules \ ws \ lib \ websocket.js:800:20) 

您可以看到错误是在RichEmbed构造函数中,我的Discord.js版本也是'12 .2.0',有什么想法吗?

解决方案

Discord.RichEmbed 在v12中已删除.

只需使用 Discord.MessageEmbed .

基本上是相同的.只是一个新名字.

新文档: https://discord.js.org/#/docs/main/v12/class/MessageEmbed

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?

解决方案

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.org/#/docs/main/v12/class/MessageEmbed

这篇关于如何修复RichEmbed Discord.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆