Discord.js how to send embed to a specific channel - discord.js

How do i send embed to a specific channel.
dont mind the code below thats just my example on how i do it
id = client.channels.cache.get("id")
client.once('ready', () => {
embed = new Discord.MessageEmbed();
embed.setTitle('example')
embed.setAuthor(client.user.tag)
embed.setDescription('example')
id.send({ embeds: [embed] })
})

just make it embed
client.on('ready', () => {
client.channels.fetch('<channel id>')
.then(channel => {
channel.send("Hello here!");
})
});

You will need to fetch the channel.
client.once('ready', () => {
const channel = client.channels.cache.get('ID_HERE')
let embed = new Discord.MessageEmbed()
.setTitle('example')
.setAuthor(client.user.tag)
.setDescription('example')
channel.send({ embeds: [ embed ] });
})
I've added channel into the ready event which should fix the problem.

Related

Embed stated not being sent to channel

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
});
const { EmbedBuilder } = require('discord.js');
// All partials are loaded automatically
//const Discord = require('discord.js');
client.on('ready', async () => {
console.log(`${client.user.username} is ready!`);
})
client.on('guildCreate', (g) => {
const channel = g.channels.cache.find(channel => channel.type === 'GUILD_TEXT' && channel.permissionsFor(g.me).has('SEND_MESSAGES'))
channel.send("Thanks for inviting flappy dank! Please run the command !run to get started!");
})
client.on("messageCreate", async (message) => {
if (message.content == '!testcmd') {
const illla = new EmbedBuilder()
.setColor(FF0000)
.setTitle('Members Generator 2.0!')
.setDescription('testing testing 123 123')
.setTimestamp()
.setFooter({ text: 'wow a footer'});
message.channel.send(illla)
}
})
I have tried the code above, when I run the command ‘!testcmd’, it does not output any embed. i have searched online for solutions, but none working. I expect and embed to be outputted, yet it doesn’t return any errors. Any advice would be appreciated!
You're using discord.js v14. There's a changes about sending Embeds
const illla = new EmbedBuilder()
.setColor(FF0000)
.setTitle('Members Generator 2.0!')
.setDescription('testing testing 123 123')
.setTimestamp()
.setFooter({ text: 'wow a footer'});
message.channel.send(illla) //The Changes is in here
The comment line should change as:
message.channel.send({embeds: [illla] });
Click here to see more about EmbedBuilder

Discord js, Bot can only find itself until someone else send a message

I was trying to get all the members of a role but i can only get the bot until someone else send a message then i can see them too
here is my code
const matches = require("../differents-matches")
module.exports = (client) => {
setInterval(async () => {
/*const allmatch = await matches.
where('_notified').exists(false).
where('_startDate').lt(Date.now()).
where('_endDate').gt(Date.now())
allmatch.forEach(element => {
})*/
console.log(client.guilds.cache.get('1050150840813498401').roles.cache.get('1050889003110506516').members.map(m => m.user.id))
//
}, 5000)
}
i tried the solution proposed in this post but the problem is still here
i have all the intents needed :
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers], fetchAllMembers: true });
and i did activate the server member intent in the bot options, i can't find any other thing to try. If you have an idea of what is the problem please leave a message.
It is expected, actually the fetchAllMembers client option disappeared with Discord.js v13.
You should now fetch the guild members manually:
const matches = require("../differents-matches")
module.exports = (client) => {
setInterval(async () => {
/*const allmatch = await matches.
where('_notified').exists(false).
where('_startDate').lt(Date.now()).
where('_endDate').gt(Date.now())
allmatch.forEach(element => {
})*/
const guild = client.guilds.cache.get('1050150840813498401');
await guild.members.fetch(); // do what fetchAllMembers previously did
console.log(guild.roles.cache.get('1050889003110506516').members.map(m => m.user.id))
//
}, 5000)
}

Discord bot not coming online despite no error messages?

I have recently spent a long time making a discord ticket bot, and all of a sudden now, it isnt turning on. There are no error messages when I turn the bot on, and the webview says the bot is online. I am hosting on repl.it
Sorry for the long code, but any genius who could work this out would be greatly appreciated. Thanks in advance.
const fs = require('fs');
const client = new Discord.Client();
const prefix = '-'
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles){
const command = require(`./commands/${file}`)
client.commands.set(command.name, command);
}
require('./server.js')
client.on("ready", () => {
console.log('Bot ready!');
client.user.setActivity('-help', { type: "LISTENING"} ).catch(console.error)
})
client.on("message", async (message) => {
if (message.author.bot) return;
const filter = (m) => m.author.id === message.author.id;
if (message.content === "-ticket") {
let channel = message.author.dmChannel;
if (!channel) channel = await message.author.createDM();
let embed = new Discord.MessageEmbed();
embed.setTitle('Open a Ticket')
embed.setDescription('Thank you for reaching out to us. If you have a question, please state it below so I can connect you to a member of our support team. If you a reporting a user, please describe your report in detail below.')
embed.setColor('AQUA')
message.author.send(embed);
channel
.awaitMessages(filter, {max: 1, time: 1000 * 300, errors: ['time'] })
.then ( async (collected) => {
const msg = collected.first();
message.author.send(`
>>> ✅ Thank you for reaching out to us! I have created a case for your inquiry with out support team. Expect a reply soon!
❓ Your question: ${msg}
`);
let claimEmbed = new Discord.MessageEmbed();
claimEmbed.setTitle('New Ticket')
claimEmbed.setDescription(`
New ticket created by ${message.author.tag}: ${msg}
React with ✅ to claim!
`)
claimEmbed.setColor('AQUA')
claimEmbed.setTimestamp()
try {
let claimChannel = client.channels.cache.find(
(channel) => channel.name === 'general',
);
let claimMessage = await claimChannel.send(claimEmbed);
claimMessage.react('✅');
const handleReaction = (reaction, user) => {
if (user.id === '923956860682399806') {
return;
}
const name = `ticket-${user.tag}`
claimMessage.guild.channels
.create(name, {
type: 'text',
}).then(channel => {
console.log(channel)
})
claimMessage.delete();
}
client.on('messageReactionAdd', (reaction, user) => {
const channelID = '858428421683675169'
if (reaction.message.channel.id === channelID) {
handleReaction(reaction, user)
}
})
} catch (err) {
throw err;
}
})
.catch((err) => console.log(err));
}
})
client.login(process.env['TOKEN'])
Your problem could possibly be that you have not put any intents. Intents look like this:
const { Client } = require('discord.js');
const client = new Client({
intents: 46687,
});
You can always calculate your intents with this intents calculator: https://ziad87.net/intents/
Side note:
If you are using discord.js v14 you change client.on from message to messageCreate.

how do i embed my bots reply with say command discord.js

on my say command it's not embedded so it lets members #everyone I want to embed the bot's reply to prevent that.
i tried other embeds but they did not work out due to them being
outdated i tried my own but it did not work
command I use:
client.on('message',
function(msg){
if(msg.content === "v!say"){
I don't lnow what to put after
There are several things you could do on this
FYI message is deprecrated and you should use the event listener below:
client.on(`messageCreate`, async (msg) => {
// code here
};
Prevent #everyone and #here
if(msg.content === `v!say` && !msg.content.includes(`#everyone`) && !msg.content.includes(`#here`){
let message2send = //however you already do this
await msg.channel.send({
content: message2send,
});
}
Embed Message
const { MessageEmbed } = require(`discord.js`);
//put at top of file
if(msg.content === `v!say`){
let message2send = //however you already do this
let embed = new MessageEmbed()
.setDescription(message2send)
await msg.channel.send({
embeds: [embed],
});
}
Do Both
const { MessageEmbed } = require(`discord.js`);
//put at top of file
if(msg.content === `v!say` && !msg.content.includes(`#everyone`) && !msg.content.includes(`#here`){
let message2send = //however you already do this
let embed = new MessageEmbed()
.setDescription(message2send)
await msg.channel.send({
embeds: [embed],
});
}
UPDATE: this answer is not for Discord.js v14+ as MessageEmbed is now EmbedBuilder

How do you make a bot that sends embed welcome messages?

I currently am having trouble running this code it used to stop the bot/replit when a person joins the bot/replit now it declares it as an empty message
let Discord = require("discord.js");
let client = new Discord.Client();
client.on("ready", () => {
client.user.setPresence({ 'activity': { name: "Test}})
})
client.on('guildMemberAdd', member => {
const embed = new Discord.MessageEmbed()
.setTitle(`Welcome ${member.user.tag}!`)
.setDescription(`You are member ${member.guild.memberCount}`)
const channel = member.guild.channels.cache.find(ch => ch.name === 'welcome-channel')
channel.send({
embeds: [embed]
})
})
client.login("")
You can use client.on('guildMemberAdd') and this for the embed =>
client.on('guildMemberAdd', member => {
const embed = new MessageEmbed()
.setTitle(`Welcome ${member.user.tag}!`)
.setDescription(`You are member ${member.guild.memberCount}!`)
const channel = member.guild.channels.cache.find(ch => ch.name === 'welcome-channel')
channel.send({
embeds: [embed]
})
})

Resources