[英]my discord.js code says it cant output an empty message even tho it shouldnt be empty
I have a discord.js bot and I wanted to add an info command.我有一个 discord.js 机器人,我想添加一个 info 命令。 I told it to get the user info and it spat this out in the console:
我告诉它获取用户信息,然后它在控制台中吐出:
(node:15012) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
(node:15012) 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:15012) [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.
(node:15012) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
(node:15012) 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: 2)
(node:15012) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
(node:15012) 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: 3)
(node:15012) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async RequestHandler.push (C:\Users\jakub\OneDrive\Počítač\da discord bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
(node:15012) 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: 4)
And this is my code这是我的代码
function info(){
message.channel.send(message.mentions.users);
else if (command === "info"){
if (!args[0]){
return message.channel.send("You Need to provide an argument");
}
else if (message.guild.member(message.mentions.users.length === 0)){
return message.channel.send("You Need to Ping someone!");
}
message.channel.send(info.username);
message.channel.send(info.createdAt);
message.channel.send(info.id);
message.channel.send(info.joinedAt);
}
);
How can I 1. improve my code, 2. help fix the problem?我怎样才能 1. 改进我的代码,2. 帮助解决问题?
Let's just pretend I didn't see that else if
going for a walk in your code block. else if
。
function info() {
message.channel.send(message.mentions.users);
if (command === "info") {
if (!args) { // [0] is useless here
return message.reply("You Need to provide an argument");
} else if (!message.mentions.users) {
return message.reply("You Need to Ping someone!");
}
message.channel.send(`${info.username}\n${info.createdAt}\n${info.id}\n${info.joinedAt}`)
}
};
I'll add that I did not understand a thing about your code.我要补充一点,我对您的代码一无所知。 Here's what I changed:
这是我更改的内容:
If that's the only code concerned by the error you gave, there's a high chance that yes, you're trying to send empty messages: where's that info
even defined?如果这是您给出的错误所涉及的唯一代码,那么很有可能是的,您正在尝试发送空消息:该
info
甚至在哪里定义?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.