#Welcome message isn't working.
16 messages · Page 1 of 1 (latest)
• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.
bot@ /root/bot
└── [email protected]
node -v v18.12.1
There are no errors/logs.
index.js:
const path = require("node:path");
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const { token } = require("./config.json");
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.commands = new Collection();
const foldersPath = path.join(__dirname, "commands");
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
client.on("guildMemberAdd", (member) => {
console.log(`${member.user.tag} has joined the server!`);
welcome.execute(member);
});
const welcome = require("./message/welcome.js");```
welcome.js:
module.exports = {
name: "welcome",
execute(member) {
const channel = member.guild.channels.cache.get("925323965591851018");
if (!channel) return console.log("Channel not found.");
channel.send("Welcome to the server, ${member}!");
},
};
You need GuildMembers intent
You need it in your client options
const path = require("node:path");
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const { token } = require("./config.json");
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers] });```
Like this?
Yes
Thanks! 🙂
Popular Topics: Gateway Intents