【发布时间】:2021-02-10 22:33:54
【问题描述】:
创建了一个禁止成员的不和谐机器人我更喜欢在禁止某人后回复消息嵌入但我所能做的只是一条普通消息我不知道为什么即使我有 discord.js 也无法创建嵌入迄今为止 (v12)
我得到的错误:
(node:9604) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'MessageEmbed' of undefined
at Object.execute (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\commands\ping.js:7:40)
at Client.<anonymous> (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\main.js:52:35)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Users\Som3a12 RL\Desktop\Advanced coding\discord bot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (events.js:315:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9604) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9604) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我的代码:
const Discord = require('discord.js');
const { MessageEmbed } = require("discord.js");
module.exports = {
name: 'ping',
description: "this is a ping cmd",
execute(message, args, Discord, client) {
const embed = new Discord.MessageEmbed()
.setTitle('Bots ping')
.setColor('RANDOM')
.setDescription(`Latency is ${Date.now() - message.createdTimestamp}ms.
API Latency is ${Math.round(client.ws.ping)}ms`);
message.channel.send(embed)
}
}
【问题讨论】:
-
您有两个
Discord变量,似乎您没有将一个传递给execute(message, args, Discord, client)方法。您可能应该从该列表中删除Discord并使用execute(message, args, client),但我不确定您如何称呼execute。 -
@ZsoltMeszaros 我照你说的做了,但现在我收到一个新错误:
const embed = new Discord.MessageEmbed() ^ ReferenceError: Discord is not defined
标签: javascript node.js discord discord.js bots