I host my bot on glitch. And when i try to send an embed, nothing happens. Why is this happening? How can i fix it?
Look for the error in the code.
When i run the code locally it works, but when i run it on glitch, it doesn’t.
Show us the code and what library are you using
also what errors are in console
I use discord.js v12. One of my embeds code:
bot.on("messageDelete", async message => {
if (message.channel.type === "dm") return;
let logChannel = message.guild.channels.cache.find(ch => ch.id === "714042162370707566");
let delEmbed = new Discord.MessageEmbed()
.setTitle("Message Deleted")
.setColor("#5a03fc")
.addField("Author", message.author.tag, true)
.addField("Channel", message.channel, true)
.addField("Message", message.content)
.setFooter(`Spood's Lounge | Message ID: ${message.id} | Author ID: ${message.author.id}`);
logChannel.send({ embed: delEmbed });
});
Doesn’t work on glitch, works when i start it locally.
Also code on glitch and my pc are the same
My friend, tell me why you search for a channel using the find method and provide data from the get method.
If you do find, do this:
let logChannel = message.guild.channels.cache.find(ch => ch.name === 'channel-name');
if get like this:
let logChannel = message.guild.channels.cache.get(ch => ch.id === '714042162370707566');
I do the logic discord.js 11.6.4.
P.S. Better to use version 11.6.4
@Programmer-Pro, use this code:
bot.on("messageDelete", async message => {
if (message.channel.type === "dm") return;
let logChannel = bot.guilds.cache.get(message.guild.id).channels.cache.get(ch => ch.id === "714042162370707566");
let delEmbed = new Discord.MessageEmbed()
.setTitle("Message Deleted")
.setColor("#5a03fc")
.addField("Author", message.author.tag, true)
.addField("Channel", message.channel, true)
.addField("Message", message.content)
.setFooter(`Spood's Lounge | Message ID: ${message.id} | Author ID: ${message.author.id}`);
logChannel.send(delEmbed);
});
When i use .get i get TypeError: Cannot read property 'send' of undefined
. This is not the problem now. Just bot can’t send embeds when the bot is on glitch. (It works when i host it locally
Try This
let logChannel = message.guild.channels.cache.get("714042162370707566");
If won’t work, try this also
let logChannel = bot.channels.cache.get("714042162370707566");
@Programmer-Pro, I have everything built on .get since I have a global bot with channel settings. Everything works according to the .get method there.
@Programmer-Pro, use this code:
message.guild.channels.cache.get('714042162370707566').send(delEmbed);
Issue is not when the bot finds/gets the channel. But with embeds. I have some embeds, then i try to send them. But it doesn’t send them. (Works when i host it locally with same code)
I just used eval to see the error, and the error is:
TypeError: fields.flat is not a function
How can i fix it?
Oops. Maybe i’m on the wrong version of node. Sorry.
Yes it requires node 12 or above version.
Use node v12
to fix this issue. In node v8 the fields will not work.