Reputation: 13
I don't know what the problem is, here is the code I am using, including the line that is meant to send it to the specified channel:
const Discord = require('discord.js')
const client = new Discord.Client();
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`)
client.guild.channels.cache.get(`801193981115367496`).send(embed)
})
client.login('login in here');
It is not sending this embed to the channel (by ID). Can anyone see where I am wrong?
update it is now working, but still does not send the code to the channel when i message in it. the Terminal also shows this:
TypeError: Cannot read property 'channels' of undefined
Upvotes: 0
Views: 128
Reputation: 2023
This bot would send an embed every time a user sent a message in any channel.
You also have a typo at your client.on("message", (_message) => {
This needs to be:
client.on("message", message => {
Also, you need the client#channels#cache#get
to be:
message.guild.channels.cache.get('801193981115367496').send(embed);
Since the ID is a string, it needs to be held in inverted commas or quotation marks.
As mentioned by Rémy Shyked, quoting the linter from VSCode:
Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as integers
The ID value is too large to be treated as an integer accurately
As mentioned above, your bot is going to send this embed every time a message is sent. Here is how you would make it respond to a basic help command (without using a handler):
const Discord = require('discord.js')
const client = new Discord.Client();
client.on("message", message => {
if (message.content.toLowerCase() === '!help') {
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.guild.channels.cache.get('801193981115367496').send(embed);
};
});
client.login('client login here');
Also, please use semi-colons, and stop using backticks (`) when they aren't necessary - it saves a lot of errors later.
Upvotes: 2