0

I know this is such a basic question, but 1. I'm new to programing in discord.js (I programmed before in HTML but this is different) 2. I'm very young (I'm a kido LOL)

Ok, so my question is: how do I make a function at my bot that sends a welcome message on a special channel an a DM to the person who joined saying something like "Welcome" ?

I'm asking this cuz I searched on the entire web and I didn't find something that I really understand.

P.S. I would really appreciate if you can add comments with explications.

THANKS IN ADVANCE!

  • 1
    To better understand how to write a good question and get relevant answers, please read our [Welcome Tour](https://stackoverflow.com/tour) to and [How ask a good question](https://stackoverflow.com/help/how-to-ask) articles. – KazikM Dec 04 '20 at 09:21
  • Ok, but you I said i'm a kid and my english is pretty bad cuz i'm not from England or USA... But if you could help me, it will be grate! –  Dec 04 '20 at 10:04

1 Answers1

0

You can use the guildMemberAdd event to detect when a member joins a guild, ChannelManager#cache to send a message to a certain channel, and GuildMember#send() to send a message to a certain member.

<client>.on('guildMemberAdd', (member) => {
  // use either `.get('id')` or `.find((c) => c.name === 'name'`
  const channel = member.guild.channels.cache.get('Channel ID');
  channel.send(...); // send to a channel
  member.send(...); // dm the member
});
Lioness100
  • 8,260
  • 6
  • 18
  • 49
  • I really don't understand the first comment (// use either `.get('id')` ...). What do you mean, what should I choose and how can I use it? If I copy-paste your code I get an error: SyntaxError: Unexpected token '<' . It refers at the first arrow-function, or how it is called... (=>) –  Dec 04 '20 at 17:05
  • Your error is referring to ``, which is a placeholder for your client instance. When running this code, replace `` with your discord.js client. My first comment is saying you should either use [`Collection#get()`](https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=get) or [`Collection#find()`](https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=find) – Lioness100 Dec 04 '20 at 17:23
  • Is there any major difference between Collection#get() and Collection#find() ? –  Dec 04 '20 at 17:28
  • `Collection#get()` will get an element by its key. In this case, the channel's ID. `Collection#find()` will get the first element that passes the given function. – Lioness100 Dec 04 '20 at 20:49