简体   繁体   English

我收到此错误,我该如何解决? DiscordAPIError:无法发送空消息

[英]I got this error, how can i fix? DiscordAPIError: Cannot send an empty message

How can I fix this?我怎样才能解决这个问题?
Error: UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message错误:UnhandledPromiseRejectionWarning:DiscordAPIError:无法发送空消息

Code:代码:

let y = process.openStdin()
y.addListener('data', res => {
    let x = res.toString().trim().split(/ +/g)
    if (!x) return;
    client.channels.cache.get("736725455599697980").send(x.join(" "));
});

The problem comes from this line:问题来自这一行:

if (!x) return;

You should use x[0] as your return condition instead of just x .您应该使用x[0]作为您的返回条件,而不仅仅是x An empty array is still an array, and can thus pass your current requirement without issue.空数组仍然是一个数组,因此可以毫无问题地通过您当前的要求。

However, discord.js cannot send an empty array, which is why you're getting your error.但是, discord.js无法发送空数组,这就是您收到错误的原因。


Quick Demonstration:快速演示:

 const example = () => { // even if x is an empty array let x = []; // it will still be defined, thus passing your condition if (x) return; // however, when you try to send it as a string, nothing shows up, // as it is empty. that's why you're getting you're error console.log(x.toString()); }; example()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决:“ DiscordAPIError:无法发送空消息” - How to fix : “DiscordAPIError: Cannot send an empty message” 如何修复“DiscordAPIError:无法向该用户发送消息”? - How can I fix `DiscordAPIError: Cannot send messages to this user`? 执行歌词命令时出现此错误:DiscordAPIError:无法发送空消息 - I have this error when i execute my lyrics command : DiscordAPIError: Cannot send an empty message 我无法解决此问题(节点:15320)UnhandledPromiseRejectionWarning:DiscordAPIError:无法发送空消息 - I can't solve this problem (node:15320) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message DiscordAPIError:无法发送空消息 - DiscordAPIError: Cannot send an empty message “DiscordAPIError:无法发送空消息” - "DiscordAPIError: Cannot send an empty message" Discord bot 的 NodeJS 错误:UnhandledPromiseRejectionWarning:DiscordAPIError:无法发送空消息 - NodeJS error with discord bot: UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message DiscordAPIError:无法发送空消息(Canva) - DiscordAPIError: Cannot send an empty message (Canva) 嵌入:DiscordAPIError:无法发送空消息 - Embed: DiscordAPIError: Cannot send an empty message DiscordAPIError:无法发送带有和嵌入的空消息 - DiscordAPIError: Cannot send an empty message with and embed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM