Making a welcome message in discord.js - discord.js

I'm a starting developer in discord.js, and recently attempted at making welcome messages.
Could you help me, please?
client.on('guildMemberAdd', (member) => {
console.log(member)
const message = `Hello <#${member.id}>`
const welcomeChannel = member.guild.channels.cache.get('775672625018961940')
welcomeChannel.send(message)
})

I'm just sharing the same answer from Worthy Alpaca.
This is so that people who are googling can see the answer.
This may answer your question: Discord.js Bot Welcomes Member, Assign a Role and send them a DM
Good luck with the rest of your bot and have a nice day!

You must enable intents. See more here: https://support-dev.discord.com/hc/en-us/articles/360056426994

Related

Discord Autocode reaction reply bot (not reaction role bot)

I have been using autocode.com to create some Discord bots. I have very little programming experience and found autocode to be quite easy. However, I've tried asking a question on autocode's discord that no one seems to understand or is asking.
I am trying to create a bot that replies to reactions--but does not assign roles, but instead, provides a reply--either in thread or a DM to that user who uses that specific emoji reaction.
For example, this is what I am looking to do: if there is a bot message in #channelx, userX will react to that message with a pepperoni emoji and then a pizza bot will reply back with a message either in thread or DM such as, "Hi #userx, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order".
Autocode has a bot that can react to reactions and assign roles but I can't seem to reverse engineer it give a reply, rather than assign roles.
I appreciate any assistance. Thanks!
What does autocode use? Python or node.js? If python, you can do something like this:
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('message'):
await message.channel.send('hi')
If node.js, you can do something like this:
client.on('messageCreate', msg => {
if (msg.content === 'specific message') {
msg.reply(`response text`);
}
});
I was previously a Community Hero at the Autocode Discord server. Try finding another app through this, and if none are available, the thing to do would be looking through the API's. Here's one for messaging in general, here's one for responding, and here's one for dm-ing.
Let's say, for example, I'd be making it reply to a reaction through DM:
The first thing you do is make sure the event trigger is set to message.reaction.add. This is so that the code you will write is triggered whenever a reaction is added.
Make either a switch or if statement to change what happens depending on what reaction triggers the code. In this example, I'll just use an if statement for easy explanation.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.emoji.id == '1234567890') {
await lib.discord.users['#0.2.1'].dms.create({
recipient_id: `${context.params.event.member.user.id}`,
content: `Hi <#${context.params.event.member.user.id}>, your pizza topping has been recorded and will be ready for pickup in 15 minutes, please visit this link.com to track your order`
});
}
What this does is check if the thing that triggered this event has the emoji id equaling '1234567890': If it does, then it follows into that if statement, and if it does not, it skips over it.
In the future, please stay patient in the Autocode Discord server; The ones who are helping are also community members, similar to here. You may always ask the same question every now and then.

How to Introduce the Bot [On added to server]

I have a question regarding on how to detect if my discord bot was added to a server. I want to display an embed when they are added, an example would be:
Can someone tell me how to do this? Thanks.
You can use the
<Client>.on('guildCreate') event.
https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-guildCreate
It's simple
I suppose you want to send a message in the guild when the bot is added
client.on("guildCreate", async (guild) =>{
guild.systemChannel.send({content: `Thank's for adding me into your server`})
})

Discord Unban All User command ( js )

Just a simple unban all users in guild command for my next ban royale in Discord. Any help would be greatly appreciated!
I wrote this based on the fact that you were writing your bot in discord.js as you did not give much information when writing and all i could see was the tags.
Try this-
const member = message.member;
switch(message.content.toLowerCase()){
case (!"unban all"):
if(member.hasPermission('ADMINISTRATOR')){
message.guild.fetchBans().forEach((fB)=>{
message.guild.members.unban(fB.user.id);
})
// All Users get unbanned
} else {
// User does not have permission.
}
}
})
If this does not work please let me know.
P.S. I'm kinda new to coding so if it is wrong please don't be angry with me.

Is it possible to create a guild invite link once a bot joins said guild?

Alright, so basically I just want to know if it's possible to do what I said in the title. If so, could somebody tell me? It'd be much appreciated. Thanks!
Discord.js docs can be found here.
client.on('guildCreate', guild => {
if (!guild.me.hasPermission('CREATE_INSTANT_INVITE')) return console.log('Insufficient permission.');
guild.channels.first().createInvite()
.then(invite => console.log(invite.url))
.catch(err => console.error());
});

How do I "Link" a channel like a mention in my Discord Bot message?

I'd like our Discord Bot to mention a specific channel, and let it be clickable. I understand mentioning a user you use the user ID. I do have the channel Id, just unsure how to implement it.
You just have to do the following:
message.channel.send('Please take a look at this Discord Server channel <#CHANNELID>')
or if you get the channel id from the bot
const channel = message.guild.channels.find(channel => channel.name === 'Name of the channel');
message.channel.send(`Please take a look at this Discord Server channel <#${channel.id}>`)
Then the channel is clickable like in this screenshot:
It is simple :^)
<#channel.id>
Channels on Discord have this special kinda syntax here:
<#channel id>
As commented by Elitezen here, running toString() on a Channel can do that mention for you. Then, just send that string yourself. It's much simpler than manually doing it.
Like this if you're answering a message:
message.channel.send(message.channel.toString());
Also, like answered by others in this question, you can do that yourself if you feel like it.
If you have a Channel object already, you can do something like this (imagine your channel is named myChannel - it doesn't have to be named that, though):
message.channel.send(`<#${message.channel.id}>`);

Resources