discord.js embed Cannot send an empty message - javascript

im trying to do an embed, but every time i try using it, it says "DiscordAPIError: Cannot send an empty message"
Here is the embed and everything related to it:
client.on('message',(message) => {
if(message.author.bot) return;
let botMessageLog = new Discord.MessageEmbed()
.setAuthor(`Logs`, client.user.avatarURL())
.setDescription(`**${message.author.toString()}** said: **${message.content}** in channel **${message.channel.toString()}**`)
.setFooter(`Log system`, client.user.avatarURL())
.setTimestamp()
.setColor("FF0000");
bot.channels.cache.get("1018767166218182668").send(botMessageLog)
});

You are doing many things wrong if you are using discord js v 14
hare is a quick fix
const {Client, EmbedBuilder} = require("discord.js")
//define a new client
client.on('messageCreate',(message) => {
if(message.author.bot) return;
let botMessageLog = new EmbedBuilder()
.setAuthor({name:`Logs`,iconURL: client.user.displayAvatarURL()})
.setDescription(`**${message.author.username}** said: **${message.content}** in channel **${message.channel.name}**`)
.setFooter({text:`Log system`, iconURL: client.user.displayAvatarURL() })
.setTimestamp()
.setColor("FF0000");
bot.channels.cache.get("1018767166218182668").send({embeds:[botMessageLog]})
//you must define bot as client
})
it always better if you use the latest Version of discord js

Related

how do I make a discord bot I made configurable per server?

I recently made a discord word filter bot and I was wondering how I could make it configurable per server? I want to be able to make a command that adds words to be filtered to the code and I want people to be able to add a custom prefix per server. I also want people to be able to set their log channel per server. Can someone help me with this please? I spent a lot of time on this bot and I dont want to just keep making more of the same bot for different servers. I'm using discord.js 12.5.3. I'll attach my code below.
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', async () => {
console.log('yay, the bot is online')
client.user.setActivity('im real', {type: 'PLAYING'})
})
client.on('message', async message => {
if(message.channel.type === 'dm' || message.author.bot) return;
const logChannel = client.channels.cache.find(channel => channel.id === '921730444498726924')
let words = [“bad”, “words”, “here”]
let foundInText = false;
for (var i in words) {
if (message.content.toLowerCase().includes(words[i].toLowerCase())) foundInText = true;
}
if (foundInText) {
let logEmbed = new Discord.MessageEmbed()
.setDescription(<#${message.author.id}> Said a bad word)
.addField('The Message', message.content)
.setColor('RANDOM')
.setTimestamp()
logChannel.send(logEmbed)
let embed = new Discord.MessageEmbed()
.setDescription('That word is not allowed here')
.setColor('RANDOM')
.setTimestamp()
let msg = await message.channel.send(embed);
message.delete()
msg.delete({timeout: '3500'})
}
})
I've tried following a tutorial but it didn't help because I need one specifically for my case. If anyone could help, that would be great.

How to .deferReply to specified channel?

How can I have it so that the bot sends a message to a specific channel, while using .deferReply and .editReply? Currently, I'm getting an error saying that suggestionChannel.deferReply is not a function. Here's my code:
const { SlashCommandBuilder } = require("#discordjs/builders");
const { MessageEmbed } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("suggest")
.setDescription("Send your suggestion to the specified channel")
.addStringOption((option) =>
option
.setName("suggestion")
.setDescription("Your suggestion")
.setRequired(true)
),
async execute(interaction, client) {
var suggestionChannelID = "900982140504793109";
var suggestionChannel = client.channels.cache.get(suggestionChannelID);
const embed = new MessageEmbed()
.setColor("#0099ff")
.setTitle(`New suggestion by ${interaction.member.displayName}`)
.setDescription(`${interaction.options.getString("suggestion")}`);
await suggestionChannel.deferReply();
await suggestionChannel
.editReply({
embeds: [embed],
})
.then(function (interaction) {
interaction.react(`👍`).then(interaction.react(`👎`));
});
},
};
How can I have it so that the bot sends a message to a specific
channel, while using .deferReply and .editReply?
Well, the short answer is; you can't. But you can do this:
As the error already says, deferReply() is not a method of the TextBasedChannels class, defined by your suggestionChannel.
Instead, try sending a message to the channel instead of replying. Replies can only be executed in the interaction's channel:
var suggestionChannelID = "900982140504793109";
var suggestionChannel = client.channels.cache.get(suggestionChannelID);
const embed = new MessageEmbed()
.setColor("#0099ff")
.setTitle(`New suggestion by ${interaction.member.displayName}`)
.setDescription(`${interaction.options.getString("suggestion")}`);
// use this instead
await suggestionChannel.send({
embeds: [embed],
});
P.S side note, deferReply() starts a 15-minute timer before the interaction expires and triggers that 'x is thinking...' text to appear when the client is calculating stuff, so try to call it as soon as possible. By default, interactions expire after 3 seconds, so if your bot fails to finish whatever it needs to accomplish within that timeframe, that interaction will fail.

I'm trying to make leave/disconnect VC command for discord bot (js), I'm facing some issues discussed bellow

The code won't work perfectly, i find couple of issues:
When I'm connected to a VC and trying to attempt the command the bot leaves the VC but triggers two functions at a time i.e., General leave funtion and author not in the same channel.
When i give command being outside the VC(bot connected to the VC) the bot responds with function we are not in a same channel funtion., rather i want it to respond with you're not connected to VC
When i give command while being outside VC and bot not connected to VC, it responds nothing and at console i get error:
(node:37) UnhandledPromiseRejectionWarning: TypeError: cannot read property "id" of undefined
Code:
client.on('message', async (message) => {
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'leave') {
let authorVoice = message.member.voice;
const embed1 = new discord.MessageEmbed()
.setTitle('🚫`You are not in a Voice Channel!`')
.setColor('RED')
.setTimestamp();
if (!authorVoice.channel) return message.channel.send(embed1);
const embed2 = new discord.MessageEmbed()
.setTitle('⛔`We are not in a same Voice Channel`')
.setColor('YELLOW')
.setTimestamp();
if (authorVoice.channel.id !== client.voice.channel.id)
return message.channel.send(embed2);
const embed = new discord.MessageEmbed()
.setTitle('`Successfully left the Voice Channel`✔')
.setColor('RED')
.setTimestamp();
authorVoice.channel.leave()
message.channel.send(embed);
}
});
Can someone help me fix it?
client.voice doesn't have a channel property. It means that client.voice.channel is undefined. When you try to read the id of it, you receive the error that you "cannot read property "id" of undefined".
You probably want the connections that is a collection of VoiceConnections. A connection does have a channel property but as client.voice.connections is a collection, you need to find the one you need first.
As you only want to check if a channel with the same ID exists, you can use the .some() method. In its callback function you check if any of the connections has the same channel ID as the message author's channel ID. So, instead of if(authorVoice.channel.id !== client.voice.channel.id) you could create a variable that returns a boolean. It returns true if the bot is in the same channel and false otherwise:
const botIsInSameChannel = client.voice.connections.some(
(c) => c.channel.id === authorVoice.channel.id,
);
// bot is not in the same channel
if (!botIsInSameChannel)
return message.channel.send(embed2);
Here is the updated code if anyone watching for:
client.on('message', async message => {
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'leave') {
let authorVoice = message.member.voice;
const botIsInSameChannel = client.voice.connections.some(
(c) => c.channel.id === authorVoice.channel.id,
);
const embed1 = new discord.MessageEmbed()
.setTitle(':no_entry_sign: You are not in a Voice Channel!')
.setColor('RED')
.setTimestamp();
if(!authorVoice.channel) return message.channel.send(embed1);
const embed2 = new discord.MessageEmbed()
.setTitle(':no_entry: We are not in a same Voice Channel')
.setColor('YELLOW')
.setTimestamp();
if (!botIsInSameChannel) return message.channel.send(embed2)
const embed = new discord.MessageEmbed()
.setTitle('Successfully left the Voice Channel✔')
.setColor('RED')
.setTimestamp();
authorVoice.channel.leave();
message.channel.send(embed);
}
});

I am trying to make a guild add message

I am trying to make it so when my bot is added to another server, it will send an embed saying how many servers it's in now and the guild name and also the guild owner. I am also trying to make another embed so it tells me when it leaves a server and tells me when it joined the server first and then when it was removed and the guild name and guild owner. I use discord.js. Could someone help, please? This is my current script:
bot.on("guildCreate", guild => {
const joinserverembed = new Discord.MessageEmbed()
.setTitle("Joined a server!")
.addField("Guild name:", `${guild.name}`)
.addField("Time of join:", `${Discord.Guild.createdTimestamp()}`)
.setColor("GREEN")
.setThumbnail(guild.displayAvatarURL())
if (guilds.channel.id = 740121026683207760) {
channel.send(joinserverembed)
}
guild.channel.send("Thank you for inviting Ultra Bot Premium! Please use up!introduction and up!help for the new perks and more!")
})
bot.on("guildDelete", guild => {
const leftserverembed = new Discord.MessageEmbed()
.setTitle("Left a server!")
.addField("Guild name:", `${guild.name}`)
.addField("Time of removal:", `${createdTimestamp()}`)
.setColor("RED")
.setThumbnail(guild.displayAvatarURL())
if (guilds.channel.id = 740121026683207760) {
channel.send(leftserverembed)
}
})
I have resolved your first issue for you in the code below.
You were doing guild.channel.send(), in this case, guild represents a Discord.Guild however you're using it like it represents an instance of Message, which it does not.
You can use guild.channels.cache.find(x => x.name == 'general').send("Thanks for inviting me to this server¬!") will send a message to a channel named general in that server.
bot.on("guildCreate", (guild) => {
const joinserverembed = new Discord.MessageEmbed()
.setTitle("Joined a server!")
.addField("Guild name:", guild.name)
.addField("Time of join:", Date.now())
.setColor("GREEN")
.setThumbnail(guild.iconURL({ dynamic: true }));
bot.channels.cache.get("740121026683207760").send(joinserverembed);
guild.channels.cache
.filter((c) => c.type === "text")
.random()
.send(
"Thank you for inviting Ultra Bot Premium! Please use up!introduction and up!help for the new perks and more!"
);
});
I filter the channels in the guild, ensuring that they are not categories or voice channels, then send the welcome message to a random one.
As for your second query, you need to use a database, store the Date.now timestamp of when it was added, then once the bot has left the guild it must get the value and display its time. I haven't done this for you, but I have fixed your code:
bot.on("guildDelete", (guild) => {
const leftserverembed = new Discord.MessageEmbed()
.setTitle("Left a server!")
.addField("Guild name:", guild.name)
.addField("Time of removal:", Date.now())
.setColor("RED")
.setThumbnail(guild.iconURL({ dynamic: true }));
bot.channels.cache.get("740121026683207760").send(leftserverembed);
});

How can I make an embed with multiple pages

I have these lines of codes so far. However, I am not entirely sure how to make an embed that if the command executor reacts to an emoji it will proceed to the next embed message; and if it's someone else, it'll return.
const embed = new MessageEmbed()
.setDescription("Thank you for using Norieko, please react below to see the command list")
message.channel.send(embed)
const modEmbed = new MessageEmbed()
.setDescription("Moderation Commands: `kick`, `ban`, `purge`")
message.channel.send(modEmbed)
const miscEmbed = new MessageEmbed()
.setDescription("Misc Commands: `meme`, `server`, `user`, `help`")
message.channel.send(miscEmbed)
Using Fields
It seems you wanted to react and sends the message, this could be better and less complicate!
client.on('messageReactionAdd', async (reaction, message) => {
const embed1 = new MessageEmbed()
.setDescription('Thank you for using Norieko, please react below to see the command list')
message.channel.send(embed1).then(function(message) {
message.react('✅');
});
if (reaction.emoji === '✅') {
const embed2 = new MessageEmbed()
.setTitle('Commands')
.addField('Moderation', '`kick`, `ban`, `purge`')
.addField('Misc', '`meme`, `server`, `user`, `help`')
message.channel.send(embed2);
};
});

Categories

Resources