简体   繁体   中英

Discord.js V13 Welcome Message

I'm still fairly new to creating bots, so this welcome message worked back in discord.js v12 but no longer works for me in v13. I am trying to send a message in a specific channel when someone joins the server, but I checked, and .send does not exist on GuildChannel. I checked to documentation but they all talk about sending message embeds, but I'm just trying to send a plain message to TextChannel Here is the code.

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.on('guildMemberAdd', guildMember => {
    guildMember.guild.channels.cache.get('474431129613762571').send(`**Welcome to the discord server, <@${guildMember.user.id}>!**`);
});

I can provide more information if needed. Any help will be appreciated.

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM