I signed up just a few moments ago because something was really bothering me: I have the following code:
JavaScript
x
20
20
1
const Discord = require('discord.js');
2
const client = new Discord.Client();
3
4
client.on('guildMemberAdd', (member) => {
5
console.log('New member.')
6
const welcomeEmbed = new Discord.MessageEmbed()
7
.setImage(member.user.avatarURL())
8
.setColor('#e9fa2a')
9
.setAuthor("Mangoly Assistant")
10
.setTitle("New member in server")
11
.setDescription('Welcome <@${member.id}> to the server! If you are new, please be sure to check out or rules channel and some useful links. We are glad to be having you here, everyone wave hello! :wave:')
12
.setFooter('Created by kostis;#4464. || Mangoly Assistant')
13
client.channels.cache.get('825130442197434418').send(welcomeEmbed)
14
});
15
16
client.once('ready', () => {
17
console.log('Bot is ready')
18
})
19
20
client.login(nice try);
For some reason, when I leave and rejoin the server, the embed isn’t sending at all to the channel. I am getting no errors in the console. Any ideas on what may have gone wrong? Thanks. 🙂
Advertisement
Answer
You need ‘Server Members Intent’ enabled when you invite the bot. Go to Discord Developer Portal > Bot > Scroll to bottom > make sure server members intent is checked
You should also be able to enable it manually in your code, but idrk how to do it. I think it’s like this:
JavaScript
1
7
1
//Client declaration
2
const client = new Discord.Client({
3
ws: {
4
intents: ['GUILD_MEMBERS']
5
}
6
})
7
Also, quick thing: to use ${variableHere} in a string, it must be a string with backticks ( ` ), like this:
JavaScript
1
4
1
var a = 'abc';
2
var b = '${a}d' //returns ${a}d
3
var c = `${a}d` //returns abcs
4