I was trying to write in an embed in my discord music bot command to tell the author of the command when and what the bot was playing.
Now, I've tried passing in different arguments (such as messageembed itself) and this isn't working.
I've only been coding for maybe 6 months now, so I'm not the best
here is my code (the bit that I'm having trouble with at least)
const song_queue = queue.get(guild.id);
if (!song) {
song_queue.voice_channel.leave();
queue.delete(guild.id);
return;
}
const stream = ytdl(song.url, {filter: 'audioonly'});
song_queue.connection.play(stream, {seek: 0, volume: 0.5})
.on('finish', () => {
song_queue.songs.shift();
video_player(guild, song_queue.songs[0]);
});
const replyEmbed = new Discord.MessageEmbed()
.setColor('#FF2D00')
.setTitle('🎶 Now Playing 🎶')
.setDescription(`${song.title} [${message.author}]`)
await song_queue.text_channel.send(replyEmbed)
}
It looks like the code that you have is just a snippet taken from your file, but from the error I can assume that Discord has not been defined.
Please make sure to include this at the top of your file:
const Discord = require("discord.js");
It seems you may have forgotten to require discord.js. Do this like so:
const Discord = require('discord.js');
If you have got something that looks like this at the top of the file, but you have a different constant name, i.e. not Discord, replace Discord in Discord.MessageEmbed() with whatever your constant is called.
Related
How to send a separate embed message to a channel different from where the slash command was executed? My current code is the following block.
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, Guild } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('arrest')
.setDescription('puts the member to jail')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to arrest')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason for arrest'))
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
async execute(interaction) {
const messageEmbed = new EmbedBuilder()
.setTitle('ARRESTED!')
.setDescription(`***${interaction.options.getUser('target').tag}*** *broke a leg. Oops.*`)
.setColor(0xBD7A21)
.setImage('https://eca.astrookai.repl.co/media/arrest.gif')
await interaction.reply({embeds: [ messageEmbed ]});
},
};
Sending a separate embed object to a different channel is intended for channel logging for moderation actions in the server and I would like to know how to achieve this, thank you.
You can use <channel>.send() for this. In which <channel> is your channel object. You can get the channel in a multiple of different ways but this is probably the easiest:
logChannel = <interaction>.guild.channels.fetch(SNOWFLAKE_ID)
Then, you can send your embed to the logchannel like so:
logChannel.send({ embeds: [YOUR_EMBED] });
To account for every command, the easiest way is to do this in your interactionCreate event
If you need more context, you can check out this example which "logs" an embed to the logChannel.
I want to have a very simple command where i make a command and add details with paragraphs.
The output handled by the bot is very weird. I have similar commands with bots from carl bot but in my personal bot it doesnt work.
const Discord = require('discord.js');
let config = require('../config.json');
module.exports = {
name: 'cm',
description: 'Comando',
execute(message, args){
let embed = new Discord.MessageEmbed()
.setColor("#47e10c")
.setDescription(args)
.setFooter(`${config.SERVER_LOGO}`)
message.channel
.send(embed)
}
}
It stays like this
Post in discord
It all depends on how you defined args, we generally define them as
const prefix = "!";
const args = <message>.content.slice(prefix.length).trim().split(/ +/g);
And they return an array of arguments for suppose
// !command hello there would return:
args = ["hello",'there"];
Now to set them as your description in MessageEmbed, you have to join them as a string, you may use array.join() method for the same, so you may do something like this:
const { MessageEmbed } = require ("discord.js");
message.channel.send(new MessageEmbed().setDescription(args.join(" ")));
so i tried making an embed. this is the code for it
const Discord = require('discord.js')
//example (inside of a command)
const embed = new Discord.messageEmbed()
embed.setAuthor(`Phaze Bot`)
embed.setTitle(`Commands List`)
embed.setDescription(`$kick: kicks a member \n $ban: bans a member \n $help music: displays music commands \n $help: displays the help screen`)
message.channel.send({embed});
Update so now i got that working, but the bottom line of the code sends
Blockquote
ReferenceError: message is not defined
i now need a fix on this if anyone can help
Put the function inside a on event:
const Discord = require('discord.js')
const client = new Discord.Client();
client.on("message", (message) => {
const embed = new Discord.messageEmbed()
embed.setAuthor(`Phaze Bot`)
embed.setTitle(`Commands List`)
embed.setDescription(`$kick: kicks a member \n $ban: bans a member \n $help music: displays music commands \n $help: displays the help screen`)
message.channel.send(embed);
})
If you want to send the message to specific channel as you mentioned, you would want to use something like this:
client.channels.cache.get(CHANNEL_ID).send(embed)
I was trying to get the reaction roles for my bot and what do I do?
if (message.content === '!Sun rr') {
const exampleEmbed = new Discord.MessageEmbed()
.setTitle('Reaction Roles')
.setDescription('React to get your roles!');
message.channel.send(embed).then(msg => msg.react(':x:'))```
You define a variable exampleEmbed, then reference embed. If you were trying to reference the example embed, your code should look like this:
if (message.content === "!Sun rr") {
const exampleEmbed = new Discord.MessageEmbed()
.setTitle("Reaction Roles")
.setDescription("React to get your roles!");
message.channel.send(exampleEmbed).then((msg) => msg.react(":x:"));
}
You defined the embed as exampleEmbed but you called embed. The bot tries to send embed, even though it isn't defined. I suggest changing exampleEmbed to something like reactionRoleEmbed and make sure you change embed to the name of the constante.
So it's my first ever time coding and i'm creating a discord bot. It's all been going fine until I try to run the bot.js file on commmand line (using "node bot.js")
But It just comes up with a bunch of errors.
My Code:
const Discord = require('discord.js');
const client = new Discord.Client();
const auth = require('./auth.json');
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
});
client.login(auth.token);
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
});
Question: Will you re-post you error picture? When you click on it it says the page doesn't exist.
PLEASE READ ALL BEFORE MAKING CHANGES!
First (Bad) Guess: But without the picture, I would guess (and this is not a good guess) that it's because "client.login(auth.token)" isn't at the bottom. Another guess is that ".content ===" does nothing. You should try and remove ".content" to see if it then works.
Here is your code with just that change:
const Discord = require('discord.js');
const client = new Discord.Client();
const auth = require('./auth.json');
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`)
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong')
}
});
client.login(auth.token);
Logging bot is ready: The is also some other things I think you should change, this changing "client.user.tag" to "client.user.username" to instead show the bot's username. Another thing is "msg.content" I'm pretty sure this does nothing, and should be changed to just "===", there are some other ones, but that's my favorite one because it's the least amount of characters and easiest to type.
Here is your code with all of these changes:
const Discord = require('discord.js');
const client = new Discord.Client();
const auth = require('./auth.json');
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`)
});
client.on('message', msg => {
if (msg === "ping") {
msg.reply('pong')
}
});
client.login(auth.token);
Token (& patrik's answer): (No hate to patrik) What patrik says that putting your token in the actual script will help (It won't, and makes it easier to hack), now while I do this, I really don't care if my bot gets hacked, it's in one server. He/She also says that the token error means that discord.js can't get the token, this is a node.js error, not a discord.js error. You probably messed up on writing a piece of code, that is likely in "auth.json". You should probably re-run through your files before doing any of these changes.
A auth/config/token (token file) .json file should look like this:
{
"token":"TOKEN-HERE"
}
And then it should be used by doing
const auth|config|token = require(./auth|config|token.json);
client.login(auth.token);
I hope this helps with coding your bot!
It's because the node.js version is not updated to be compatible with the new discord.js version
First, install old version of discord.js in console type
npm i discord.js.old#11.6.4
In your script change
this:
const Discord = require('discord.js')
To:
const Discord = require('discord.js.old')
Glad to see you are into making bots too!
I would firstly suggest replacing all those "client" words with "bot"
The unexpected token might be because of that above mentioned thing or that your token is not just simply there.
Remove line:
client.login(auth.token);
and replace it with:
bot.login('YOUR-TOKEN-HERE');
You can check what if your token at the Discord Developer page