简体   繁体   中英

Discord - RichEmbed - Empty Message - Play command for Music

I'm trying to setup my bot to where whenever I run "=play" it will post an embed stating what is being played. But every time I try to run it the video loads fine, but the embed itself won't. Does anyone have any tips as to how to get it to work?

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});

};

Once you finished making your embed, you forgot to add ; to the end of the statement in both embeds. Try fixing that problem and see if it works.

I found out the problem. message.channel.send({playing}); was incorrect. ({playing}) doesn't need to have the brackets around it, it just needs to sit inside the parenthesis.

So instead of message.channel.send({playing}); it would be message.channel.send(playing); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM