Welcome message when joining discord Server using discord.js
If you read the documentation, there's is no message
parameter, only member
. You will have to get the guild's channel ID first.
Try something like this:
bot.on('guildMemberAdd', member => {
member.guild.channels.get('channelID').send("Welcome");
});
Discord.js V13 Welcome Message
You need GUILD_MEMBERS
intent in both the code and discord developer portal.
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS //also enable in discord developer portal
]
})
To answer the other part of your other question, the .send
exists on TextChannel
s. TextChannel
extends BaseGuildTextChannel
which extends GuildChannel
. It's like this because it can be a VoiceChannel
!
Discord.JS: Welcome message
client.on("guildMemberAdd", (member) =>
client.channels.cache.get("789830758331318273").send({
//put your channel id in replace of "789830758331318273"
embed: {
title: "Joined",
description: `\n <@${member.id}> joined the server. There are now \`${member.guild.memberCount}\` in the server \nWelcome <@${member.id}> :wave:`,
color: config.color,
},
})
);
discord.js event handler welcome message
The issue lies within the welcome code.
In the handler code you have the following line:
client.on(event.name, (...args) => event.execute(...args, Discord, client));
This triggers the client on the name property set in the welcome code.
You currently have it set to welcome
, which is not a valid event.
The bot is now listening for a welcome event, which will never happen.
First course of action is setting the name property to guildMemberAdd
like this:
module.exports = {
name: 'guildMemberAdd',
//the rest of the code
Then you have another issue.
Within the welcome code you have client.on()
again.
This will never work, unless by some incredibly lucky chance 2 people join within a millisecond of each other, but even then you'll only have 1 welcome message.
Removing the following:
client.on('guildMemberAdd', (member) => {
//code
})
will fix that issue.
Then the last thing to do is having the member value being imported correctly.
We do this by changing the following line:
execute(Discord, client) {
to:
execute(member, Discord, client) {
//code
The resulting code will look like this:
module.exports = {
name: 'guildMemberAdd',
once: false,
execute(member, Discord, client) {
const welcomechannelId = '753484351882133507' //Channel You Want to Send The Welcome Message
const targetChannelId = `846341557992292362` //Channel For Rules
let welcomeRole = member.guild.roles.cache.find(role => role.name === 'Umay');
member.roles.add(welcomeRole);
const channel = member.guild.channels.cache.get(welcomechannelId)
const WelcomeEmbed = new Discord.MessageEmbed()
.setTitle(`Welcome To ${member.guild.name}`)
.setThumbnail(member.user.displayAvatarURL({dynamic: true, size: 512}))
.setDescription(`Hello <@${member.user.id}>, Welcome to **${member.guild.name}**. Thanks For Joining Our Server.
Please Read ${member.guild.channels.cache.get(targetChannelId).toString()}, and assign yourself some roles at <#846341532520153088>. You can chat in <#753484351882133507> and talk with other people.`)
// You Can Add More Fields If You Want
.setFooter(`Welcome ${member.user.username}#${member.user.discriminator}`,member.user.displayAvatarURL({dynamic: true, size: 512}))
.setColor('RANDOM')
member.guild.channels.cache.get(welcomechannelId).send(WelcomeEmbed)
}
}
Happy coding!
Welcome message in a specific channel when a user joins the server. (guildMemberAdd, discord.js)
This is because you are not requesting the GUILD_MEMBERS
intent.
const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MEMBERS"] });
const { MessageEmbed } = require('discord.js');
client.on("ready", () => {
console.log("Cloud Shield has been activated.")
});
client.on("guildMemberAdd", async (member) => {
console.log(member);
});
client.login(process.env.token)
Related Topics
Can You Combine Multiple Images into a Single One Using JavaScript
How to Make a Modal Popup to Take an Input Value Using Jquery or JavaScript
Datatables/Tabletools: Format Data as Text When Exporting to Excel
How to Pass Arguments to Addeventlistener Listener Function
Regular Expression Which Matches a Pattern, or Is an Empty String
Reload Datatable After Ajax Success
Will a React Component Re-Render If Its Props Are Updated, But Don't Change in Value
Change the Arrow Buttons in Slick Slider
Javascript (+) Sign Concatenates Instead of Giving Sum of Variables
Slick Slider - How to Keep the Active Pagination (Dot) Always Centered
Set Focus to the Next Input Element
How to Create a Horizontal Scrolling Chart.Js Line Chart With a Locked Y Axis
How to Do Validation for 10 Digit Mobile Number Using Jquery
Map, and Removing Commas from an Array in JavaScript
Filereader Onload With Result and Parameter
Javascript Loop Wait Until API Call Finished