Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Discord.js嵌入错误无法发送空消息_Javascript_Discord_Discord.js - Fatal编程技术网

Javascript Discord.js嵌入错误无法发送空消息

Javascript Discord.js嵌入错误无法发送空消息,javascript,discord,discord.js,Javascript,Discord,Discord.js,因此,我试图用嵌入中显示的命令列表生成一个帮助命令。我的代码有点正常,但它抛出了一个错误“DiscordAPIError:无法发送空消息”,我已经尝试了我知道的所有内容和找到的内容,但无法修复它 这是密码 const Discord = require('discord.js'); const { prefix } = require('../config.json'); module.exports = { name: 'help', description: 'List all o

因此,我试图用嵌入中显示的命令列表生成一个帮助命令。我的代码有点正常,但它抛出了一个错误“DiscordAPIError:无法发送空消息”,我已经尝试了我知道的所有内容和找到的内容,但无法修复它

这是密码

const Discord = require('discord.js');
const { prefix } = require('../config.json');

module.exports = {
  name: 'help',
  description: 'List all of my commands or info about a specific command.',
  aliases: ['commands', 'cmds'],
  usage: '[command name]',
  cooldown: 5,
  execute(msg, args) {

    const data = [];
    const { commands } = msg.client;

    if (!args.length) {

        const helpEmbed = new Discord.MessageEmbed()
            .setColor('YELLOW')
            .setTitle('Here\'s a list of all my commands:')
            .setDescription(commands.map(cmd => cmd.name).join('\n'))
            .setTimestamp()
            .setFooter(`You can send \`${prefix}help [command name]\` to get info on a specific command!`);

        msg.author.send(helpEmbed);

        return msg.author.send(data, { split: true })
            .then(() => {
                if (msg.channel.type === 'dm') return;
                msg.reply('I\'ve sent you a DM with all my commands!');
            })
            .catch(error => {
                console.error(`Could not send help DM to ${msg.author.tag}.\n`, error);
                msg.reply('it seems like I can\'t DM you! Do you have DMs disabled?');
            });
    }

    const name = args[0].toLowerCase();
    const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));

    if (!command) {
        return msg.reply('that\'s not a valid command!');
    }

    data.push(`**Name:** ${command.name}`);

    if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
    if (command.description) data.push(`**Description:** ${command.description}`);
    if (command.usage) data.push(`**Usage:** ${prefix}${command.name} ${command.usage}`);

    data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);

    msg.channel.send(data, { split: true });
 },
};

您应该尝试替换此行:
msg.channel.send(数据,{split:true})


msg.channel.send(data.join(“”),{split:true})由于数据变量是数组而不是字符串,因此应尝试替换此行:
msg.channel.send(数据,{split:true})


msg.channel.send(data.join(“”),{split:true})由于数据变量是数组而不是字符串,因此问题在于错误状态。您试图在某处发送一条空消息

您可以尝试将
msg.channel.send(data)
替换为
msg.channel.send(data.join('\n'))
,因为
data
变量是数组


我不明白为什么发送数组不起作用。

问题在于错误状态。您试图在某处发送一条空消息

您可以尝试将
msg.channel.send(data)
替换为
msg.channel.send(data.join('\n'))
,因为
data
变量是数组



我不明白为什么发送数组不起作用。

发送数组不起作用,因为discord.js不允许它,我认为仍然是相同的结果。我认为您的问题不是试图发送数组,而是数组是空的。如果您尝试执行
var data
而不是
const data
,会怎么样?@ComputerGeek12是的,问题是cons-dat=[]但是我不能用var来替换它。如果我只是将它设置为某个值,那么命令就可以正常工作。发送数组不起作用,因为discord.js不允许这样做。很遗憾,我认为仍然是相同的结果。我认为你的问题不在于你试图发送数组,而在于数组是空的。如果您尝试执行
var data
而不是
const data
,该怎么办?@ComputerGeek12是的,问题是cons-dat=[],但我无法将其替换为var。如果我只是将其设置为某个值,则命令可以正常工作。遗憾的是,相同result@Soulhax@Soulhax您在这行上犯了同样的错误:
返回msg.author.send(数据,{split:true}
我试着把它们都替换掉了,但还是一样的。两个都替换会让事情变得更糟。当两个都被替换时:当它是原始代码时:@Soulhax什么意思更糟?添加了图片链接,这样你就可以看到相同的图片了result@Soulhax@Soulhax您在这行上犯了同样的错误:
return msg.author.send(数据,{split:true})
我尝试同时替换这两个,但还是一样的。同时替换这两个会让情况变得更糟。当两个都被替换时:当它是原始代码时:@Soulhax,什么意思更糟?添加了图片链接以便您可以看到