Heyo,
I want my bot to send a embed message to my private discord server when it joins & leaves a server. But the problem is that it does not send anything anywhere. My code looks like this:
JavaScript
x
21
21
1
exports.run = async (client, guild) => {
2
3
if(!guild.available) return
4
5
6
if(!guild.owner && guild.ownerID) await guild.members.fetch(guild.ownerID);
7
8
if(!channel) return;
9
10
const embed = new MessageEmbed()
11
.setTitle(`Bot joined a server`)
12
.setDescription(`${guild.name}`)
13
.setColor(0x9590EE)
14
.setThumbnail(guild.iconURL())
15
.addField(`Owner", "${guild.owner.user.tag}`)
16
.addField(`Member Count", "${guild.memberCount}`)
17
.setFooter(`${guild.id}`)
18
client.channels.cache.get('ID').send(embed)
19
20
}
21
Advertisement
Answer
Your code doesn’t activate upon joining the server. For that you have a nice event (that has a misleading name) guildCreate
– it is emitted whenever the client joins a guild.
So, your code should look something like this
JavaScript
1
13
13
1
client.on('guildCreate', async guild => {
2
let YourChannel = await client.channels.fetch('channelid');
3
const embed = new Discord.MessageEmbed()
4
.setTitle(`Bot joined a server`)
5
.setDescription(`${guild.name}`)
6
.setColor(0x9590EE)
7
.setThumbnail(guild.iconURL())
8
.addField(`Owner`, `${guild.owner.user.tag}`)
9
.addField(`Member Count`, `${guild.memberCount}`)
10
.setFooter(`${guild.id}`)
11
YourChannel.send(embed);
12
});
13
Same works for leaving the guild, use guildDelete
event.