I'm making a music bot, and I wanted to add an Embed when it returns a message, and I get an error saying const is not defined.
Here's my code:
const Discord = require('discord.js');
const bot = new Discord.Client({
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
const config = require('./settings.json');
const { loadCommands } = require('./utils/loadCommands');
const DisTube = require('distube');
bot.distube = new DisTube(bot, { searchSongs: false, emitNewSongOnly: true });
bot.distube
.on("playSong", (message, queue, song) => message.channel.send(
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Playing Now:')
.setDescription('`${song.name}`')
.setTimestamp()
.setFooter('Requested by: ${song.user}');
.on("addSong", (message, queue, song) => message.channel.send(
.setColor('#0099ff')
.setTitle('Added to Queue:')
.setDescription('\`${song.name}\`')
.setTimestamp()
.setFooter('${song.formattedDuration} - Requested by ${song.user}');
require('./utils/loadEvents')(bot);
bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();
loadCommands(bot);
bot.login(config.token);
And then after I run it, I get this error:
const exampleEmbed = new Discord.MessageEmbed()
^^^^^
SyntaxError: Unexpected token 'const'
←[90m at wrapSafe (node:internal/modules/cjs/loader:1024:16)←[39m
←[90m at Module._compile (node:internal/modules/cjs/loader:1072:27)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:973:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:813:14)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)←[39m
I've never used discord js, but from a quick look at the docs i guess you should do something like first declare your variable and then send it
bot.distube
.on("playSong", (message, queue, song) => {
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Playing Now:')
.setDescription('`${song.name}`')
.setTimestamp()
.setFooter(`Requested by: ${song.user}`);
message.channel.send(exampleEmbed);
}
There are 2 more problems.
.setFooter('Requested by: ${song.user}')
template string should be with back ticks ' ` ' . see below.setFooter(`Requested by: ${song.user}`)
send
method seem like they are not ' closed ' with closing )
Read more here -> embed discord