discord.js welcome message code example
Example 1: make welcome message and channel discord.js
bot.on('guildMemberAdd', async newMember => {
const welcomeChannel = newMember.guild.channels.cache.find(channel => channel.name === 'the channel name here, make sure the ')
welcomeChannel.send('Input your message here, if you want an embed then do a "let msgEmbed = new Discord.messageEmbed / and input the title and all the embed stuff, customize the message as much as you want!"')
let msgEmbed = new Discord.MessageEmbed()
.setTitle (`This is a title for a test`)
if (newMember.bot) return;
const newbieRole = newMember.roles.cache.find(role => role.name === 'Role Name here')
newMember.roles.add(newbieRole.id)
})
Example 2: how to reference the bot joining a server in discord.js
client.on('guildCreate', guild => {
const channel = guild.channels.cache.find(channel => channel.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'))
channel.send("Thanks for inviting me")
})
Example 3: welcome discord.js
client.on('guildMemberAdd', async member => {
context.strokeRect(0, 0, canvas.width, canvas.height);
context.font = '28px sans-serif';
context.fillStyle = '#ffffff';
context.fillText('Welcome to the server,', canvas.width / 2.5, canvas.height / 3.5);
context.font = applyText(canvas, `${member.displayName}!`);
context.fillStyle = '#ffffff';
context.fillText(`${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);
});