in , ,

Create Welcome Command Using guildMemberAdd event and quick.db in discord.js

we will be storing channel id by using quick.db, if you have any thoughts like why i am not using mongo and other things then i must say i just like quick.db because it is simple to use.

i will be using my command handler and if you do not know how to create command handler than you should check this post – COMMAND HANDLER

First of all we will be creating setwelcome command which will be setting welcome channel id in server variable

const Discord = require("discord.js")
const db = require("quick.db")

module.exports = {
  name: "setwelcome",
  category: "moderation",
  usage: "setwelcome <#channel>",
  description: "Set the welcome channel",
  run: (client, message, args) => {
    let channel = message.mentions.channels.first() //mentioned channel
    if(!channel) { //if channel is not mentioned
      return"Please Mention the channel first")
    //Now we gonna use quick.db
    db.set(`welchannel_${}`, //set id in var`Welcome Channel is seted as ${channel}`) //send success message

Now we will head to main file, in my case my main file name is server.js and i will be using guildMemberAdd event, when member joins it will triggered in seted channel.

const db = require("quick.db") //using quick.db package

client.on("guildMemberAdd", (member) => { //usage of welcome event
  let chx = db.get(`welchannel_${}`); //defining var
  if(chx === null) { //check if var have value or not

  let wembed = new discord.MessageEmbed() //define embed
  .setAuthor(member.user.username, member.user.avatarURL())
  .setDescription(`We are very happy to have you in our server`);
  client.channels.cache.get(chx).send(wembed) //get channel and send embed

Res>Resulting Code

Here is the resulting code – HERE

Related Posts

Written by Senpai

"This may be a virtual world,but I feel more alive here then in the real world"

Leave a Reply