Why does this not send embed to channel id? discord.js - discord.js

I've tried multiple ways to try to get it to send but it shows no error and doesn't send into channel.
const { MessageEmbed } = require('discord.js');
client.on("ready", async () => {
const embed = new MessageEmbed()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`)
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
})

in the latest Discord.js version (V14) the correct way is
const { EmbedBuilder } = require('discord.js');
client.on("ready", async () => {
const embed = new EmbedBuilder()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`);
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
});
If this is not solving your issue,
try to add a console.log(channel) just before channel.send({embeds: [embed]})
If the result is undefined, the problem is the bot can't get in your cache the channel you want. In that case you can fetch (Link to a post speaking about this)
In the other case the bot can't send a message in the channel, could be a permission issue but you can add a .then() / .catch() to see if error is showed or not.
Hope this can helps you

I think the problem is that you don't have the client to call.
const { MessageEmbed } = require('discord.js');
client.on("ready", async (/*client not found in here*/) => {
const embed = new MessageEmbed()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`)
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
})
So try to add client
const { MessageEmbed } = require('discord.js');
client.on("ready", async(client) => {
const embed = new MessageEmbed()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`)
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
})

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 My bot don't turn online but there is a simple code

My bot don't turn online but there is a simple code:
const discord = require('discord.js')
const client = new discord.Client();
const token = ('my bot token')
client.on('ready', function(){
console.log('online')
})
client.login(token)
Try this:
const discord = require('discord.js')
const client = new discord.Client();
// you will want to define some intents if you want the bot to be able to do anything
// see https://discordjs.guide/popular-topics/intents.html#enabling-intents and https://discord.js.org/#/docs/main/stable/class/Intents
const token = 'my bot token' // took away the ()
client.on('ready', () => { //removed 'function' and added => to pass everything through
console.log('online')
})
client.login(token)

Discord.js client.channel.cache.get().send() is not a Function

const Discord = require('discord.js');
const client = new Discord.Client();
const token = 'token';
client.on('ready', () => {
client.channels.cache.get('channelid').send('Test');
});
client.login(token);
Whenever I try to run this, it always says: "(node:20284) UnhandledPromiseRejectionWarning: TypeError: client.channels.cache.get(...).send is not a function"
This is not really a solution, but rather a workaround. This problem is caused probably because the channels ain't being stored on the ChannelManager cache, I don't know the solution to this (I can edit the answer if somebody does), but you could fetch the channel directly using the promise based ChannelManager.fetch(id: string), like that:
const { Client } = require('discord.js');
const client = new Client();
client.on('ready', async function() {
const channel = await client.channels.fetch('channelId');
channel.send('message');
});
client.login('token');

Removing all reactions from a message

I currently have my bot sending an embed then reacting to it.
I was wondering how I would go on removing all reactions from this message.
Code:
const { Client, MessageEmbed} = require('discord.js');
const client = new Client();
let prefix = '~';
client.on('message', async message => {
if (message.content.toLowerCase() === prefix + 'help'
const embed = new MessageEmbed()
.setTitle('Help Cmd')
.setDescription('example')
let msg = await message.channel.send(embed);
await msg.react('▶');
await msg.react('◀');
setTimeout(() => {
//Removing all reactions from msg
}, 5000);
}
You can use msg.reactions.removeAll();.

Trying to display JSON data from API as an array

So I've been trying to make a Discord Bot in Node.js, Im fetching data from an external api and using the BOT to display the data, problem is that when I call the function, its showing one by one instead of everything in one message.
I want to display everything in one message.
const token = 'my discord token is here';
const Discord = require('discord.js');
const axios = require('axios');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on('message', async msg => {
if (msg.content === '!inventario') {
let getInv = async () => {
let response = await axios.get('my api link where im getting the info is here')
let inventario = response.data
return inventario
}
let inventarioValue = await getInv ()
var inv = inventarioValue.total_inventory_count
msg.channel.send(`Total de Itens no inventário: ${inventarioValue.total_inventory_count} \nSkins:\n`);
for (var i=0;i<inv;i++)
{
var itens = inventarioValue.descriptions[i].market_name
msg.channel.send(itens);
}
}
});
client.login(token);
I want to execute this inventarioValue.descriptions[i].market_name, then after executing showing the full result instead of showing one by one.
Thanks
You can map object array element and add to message. For a better visual reflection, you can add them to embed.
const token = 'my discord token is here';
const Discord = require('discord.js');
const axios = require('axios');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on('message', async msg => {
if (msg.content === '!inventario') {
let getInv = async () => {
let response = await axios.get('my api link where im getting the info is here')
let inventario = response.data
return inventario
}
let inventarioValue = await getInv()
var inv = inventarioValue.total_inventory_count
let embed = new Discord.MessageEmbed()
embed.setDescription(`${inventarioValue.descriptions.map(val => val.market_name).join('\n')}`)
msg.channel.send(`Total de Itens no inventário: ${inventarioValue.total_inventory_count} \nSkins:\n`, embed);
}
});
client.login(token);

Resources