【问题标题】:Discord - RichEmbed - Empty Message - Play command for MusicDiscord - RichEmbed - 空消息 - 音乐播放命令
【发布时间】:2018-07-03 09:33:36
【问题描述】:

我正在尝试将我的机器人设置为每当我运行“=play”时它会发布一个嵌入说明正在播放的内容。但每次我尝试运行它时,视频加载正常,但嵌入本身不会。有没有人有任何关于如何让它工作的提示?

const Discord = require("discord.js");
const ytdl = require('ytdl-core');

exports.run = async (client, message, args, ops) => {

    const embed = new Discord.RichEmbed()
    .setAuthor('Please enter a voice channel','https://i.imgur.com/Tu6PraB.png')
    .setDescription('You must be in a voice channel to play music!')
    .setColor('#de2e43')
    if (!message.member.voiceChannel) return message.channel.send({embed});

    if (message.guild.me.voiceChannel) return message.channel.send('Sorry, the bot is already connected to the channel.');

    if (!args[0]) return message.channel.send('Sorry, please input a url following the command.');

    let validate = await ytdl.validateURL(args[0]);

    if (!validate) return message.channel.send('Sorry, please input a **valid** url following the command.')

    let info = await ytdl.getInfo(args[0]);

    let connection = await message.member.voiceChannel.join();

    let dispatcher =  await connection.playStream(ytdl(args[0], { filter: 'audioonly'}));

    var playing = new Discord.RichEmbed()
    .setAuthor('Now playing')
    .setDescription(`${info.title}`)
    .setColor('#2ecc71')

    message.channel.send({playing});

};

【问题讨论】:

  • (node:31960) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message 是我得到的错误。

标签: node.js discord.js


【解决方案1】:

完成嵌入后,您忘记在两个嵌入的语句末尾添加;。尝试解决这个问题,看看它是否有效。

【讨论】:

  • 在 Javascript 中,分号通常是可选的,这段代码中没有语法歧义,可以通过添加分号来解决。
  • 哦,不过我仍然总是使用分号。
【解决方案2】:

我发现了问题。 message.channel.send({playing}); 不正确。 ({playing}) 不需要用括号括起来,只需要放在括号内即可。

所以不是message.channel.send({playing});,而是message.channel.send(playing);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 2021-12-04
    • 2022-07-10
    • 2022-01-21
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多