gpt4 book ai didi

javascript - 无法读取未定义的属性 'MessageEmbed'

转载 作者:行者123 更新时间:2023-12-03 07:07:55 25 4
gpt4 key购买 nike

创建了一个禁止成员的不和谐机器人我更喜欢在禁止某人后回复一条嵌入的消息,但我所能做的就是一条普通消息我不知道为什么即使我有最新的 discord.js (v12) 也无法创建嵌入

我得到错误:

C:\Users\oussa\OneDrive\Bureau\Discord Bot\index.js:45
const BanEmbed = new Discord.MessageEmbed()
^

TypeError: Cannot read property 'MessageEmbed' of undefined

这是我的代码:

const { Client, Attachment, Message, Discord } = require("discord.js");
const { prefix, token } = require("./config.json");
const bot = new Client();

const ytdl = require("ytdl-core");
const request = require("request");
const cheerio = require("cheerio");

const queue = new Map();

bot.on("ready", () => {
console.log("Client is online!");
bot.user.setActivity("osu!");
bot.user.setUsername("RevolverSnake412");
});

bot.on("message", (msg) => {
const BanEmbed = new Discord.MessageEmbed()
.setColor("#5300A6")
.setTitle("title")
.setAuthor("author")
.setDescription("description")
.setThumbnail("https://image.freepik.com/free-icon/sail-boat_318-1522.jpg")
.setImage("https://img.ifunny.co/images/01b86faa3cedc450bffac646492c3a8717d30f74f41434761d45c66b9545d8c6_1.jpg")
.setFooter("footer");

switch (args[1]) {
case "ban":
const user = msg.mentions.users.first();

if (user) {
const member = msg.guild.member(user);

if (member) {
member.ban({ ression: "..." }).then(() => {
msg.channel.send(BanEmbed);
});
} else {
msg.channel.send("...");
}
} else {
msg.channel.send("...");
}

break;
}
});

bot.login(token);

最佳答案

错误出在你的解构赋值中。 Discord 不是 discord.js 的属性,因此它是未定义的。您很可能想要:

const { Client, Attachment, Message, MessageEmbed } = require("discord.js");

然后像这样实现

const BanEmbed = new MessageEmbed()

旁注,Attachment 也不是 discord.js 的有效属性,因此您很可能希望将其更改为 MessageAttachment

API 文档:https://discord.js.org/#/docs/main/stable/class/MessageAttachment

关于javascript - 无法读取未定义的属性 'MessageEmbed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64180970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com