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)
Related
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.
it should delete my message and type it as if it has said it itself, im a begginer in discord bot coding pls help
It can be done by storing the message in a variable, deleting the message, then sending the variable. An example would be:
client.on('message', async (message) => {
const content = message.content;
await message.delete();
await message.channel.send(content);
});
i'm new to programming and started making a discord bot by watching a few tutorials. I want the bot to DM the discord embed to the user who types "-buy" in a text channel. When running the code, the bot comes online and runs the "your bot name is online!" but no DM is sent. I would greatly appreciate any help. Thanks
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
client.once('ready', () => {
console.log('your bot name is online!');
});
client.on('message', message =>{
if(message.author.client) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLocaleLowerCase();
if(command === 'buy'){
const testEmbed = new Discord.MessageEmbed()
.setColor(0x7f03fc)
.setTitle('test embeddy')
.setDescription('test description woo')
.setFooter('this is the footer')
try {
message.author.send(testEmbed);
} catch {
message.reply('Sorry I cannot message you! Check if your DMs are public!')
}
}
});
client.login('');
the token isn't the problem, i deleted it so i could upload here
The message.author.client returns the bot client, and it doesn't return a boolean. So your bot is blocked from there. Try removing that code and write message.author.bot that returns a boolean if the message author is a bot user. It will work.
This is my first time using js. I need to ban a certain word in a certain channel. I don't want the message to be deleted if it is not in the specific channel.
For Example:
I want to ban the word "goodbye" in the #greeting channel
BUT
I don't want to ban the word "goodbye" In the #farewell channel
How would I go about this?
Thanks.
By the way I wanted to use example code, but none of it made any sense.
I wrote a simple example for you on how to achieve this:
const Discord = require("discord.js");
const Client = new Discord.Client();
const ForbiddenWords = {
"ChannelID": ["goodbaye", "bye"] // Greeting channel
};
Client.on("ready", () => {
console.log(`${Client.user.tag} is ready!`);
});
Client.on("message", (message) => { // Fired when the bot detects a new message.
if (message.author.bot) {return false}; // Checking if the message author is a bot.
if (ForbiddenWords[message.channel.id]) { // Checking if the current channel has any forbidden words in the ForbiddenWords Object
if (ForbiddenWords[message.channel.id].some(word => message.content.toString().toLowerCase().includes(word))) { // Checking if the message contains any forbidden words
message.delete(); // Deleting the message.
};
};
});
Client.login(process.env.DISCORD_AUTH_TOKEN);
I am trying to make a Discord bot for announcements. I want to create a command which will read the data from the message and convert it into Embedded message.
An example command: !announce Title, Description, Link, Image
const Discord = require('discord.js');
const bot = new Discord.Client();
//listener
bot.on('ready', () => {
bot.user.setGame('Hello!')
});
bot.on('message', (message) => {
if(message.content == 'text') {
const embed = new Discord.RichEmbed()
.setTitle("Title!")
.setDescription("Description")
.setImage("https://i.imgur.com/xxxxxxxx.png")
.setURL("https://google.com")
.addField("Text", true)
//Nope
.setThumbnail("https://i.imgur.com/Rmiwd1j.png")
.setColor(0x00AE86)
.setFooter("Footer", "https://i.imgur.com/xxxxxxxx.png")
.setTimestamp()
/*
* Blank field, useful to create some space.
*/
message.channel.send({embed});
}});
bot.login('token');
I want Embed to be changed based on the text.
How can I do this?
First, you'll need to detect the command: you can use String.startsWith() to detect !announce:
if (message.content.startsWith('!announce')) {...}
Then you'll have to get the other parts of the command by splitting the string: you can separate them with a comma, as you did (title, description, ...), or with whatever character you want (I'll use a comma in my example).
String.slice() will help you get rid of the !announce part, while String.split() will create an Array with the other parts.
This code will generate an embed like this from the command !announce Title, Description, http://example.com/, http://www.hardwarewhore.com/wp-content/uploads/2018/03/dcord.png
client.on("message", message => {
if (message.content.startsWith('!announce')) {
let rest_of_the_string = message.content.slice('!announce'.length); //removes the first part
let array_of_arguments = rest_of_the_string.split(','); //[title, description, link, image]
let embed = new Discord.RichEmbed()
.setTitle(array_of_arguments[0])
.setDescription(array_of_arguments[1])
.setImage(array_of_arguments[3])
.setURL(array_of_arguments[2])
.addField("Text", true)
.setThumbnail("https://i.imgur.com/Rmiwd1j.png")
.setColor(0x00AE86)
.setFooter("Footer", array_of_arguments[3])
.setTimestamp();
message.channel.send({ embed });
}
});
I suggest using the text instead of the description and remind that the second argument of the .addField() is the text, not the inline value