[英]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.