簡體   English   中英

如何修復 RichEmbed Discord.js

[英]How to fix RichEmbed Discord.js

我知道問題存在,但即使我查看了另一個問題並且我使用了“sendEmbed”而不是“發送”但似乎沒有任何效果,如果有人可以幫助解決這個錯誤,我將不勝感激:)

這是我的代碼:

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);

這是錯誤:

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)

如您所見,錯誤出現在 RichEmbed 構造函數中,我的 Discord.js 版本也是“12.2.0”,有什么想法嗎?

Discord.RichEmbed在 v12 中被移除。

只需使用Discord.MessageEmbed代替。

本質上是一樣的。 只是一個新名字。

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

Discord.RichEmbed在 V12 中被移除

嘗試這個:

const embed = new Discord.MessageEmbed()

//我嵌入

msg.channel.send(嵌入)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM