#Welcome message isn't working.

16 messages · Page 1 of 1 (latest)

unreal roost
#

I am trying to get my bot to post a welcome message in a channel as soon as a user joins the server. However I am not succeeding, I have no idea what I am doing wrong.

quick totemBOT
#

• 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.

unreal roost
#

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}!");
    },
};
modest meadow
#

You need GuildMembers intent

unreal roost
#

Will it work after I save this?

untold wind
#

You need it in your client options

candid raptorBOT
unreal roost
# untold wind 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?

untold wind
#

Yes

unreal roost
#

Thanks! 🙂