Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
Welcome System in Discord.js dosent work & no error

So I was making welcome system on my discord bot and encountered the problem where my code dosent work (dosent respond) but there is no error.

So i made command to set welcome channel --It Works
I also setted Schema (i using mongoDB) where i will save guildId, ChannelId & RoleID. --Work

Then i have file: welcomer.js which actually need to send the message when user join, but it dosent, i also dont have any errors in console:

SetChannel.js:

        async execute(interaction, client, message) {
        try {

            if(!interaction.member.permissions.has('ADMINISTRATOR')) return interaction.reply('You are not allowed to use this command')
            const channel = interaction.options.getChannel('channel')
            const role = interaction.options.getRole('role')

            Schema.findOne({Guild: interaction.guild.id}, async(err, data) => {
                if(data) {
                    data.Channel = channel.id
                    data.Role = role.id 
                    data.save()
                } else {
                    new  Schema({
                        Guild: interaction.guild.id,
                        Channel: interaction.channel.id,
                    }).save()
                }
            })
            interaction.reply(`${channel} has been set as welcome channel
${role} will be given to the new members when they join the server.`)
            //.then(console.log)
            .catch(console.error)
        }
        catch(err) {
            console.log(err)
        }
    }
}

welcomeSchema.js:

    const mongoose = require('mongoose')

const Schema = new mongoose.Schema({
    Guild: String,
    Channel: String,
    Role: String,
})

module.exports = mongoose.model('welcome-channel', Schema)

welcomer.js:

//const client  = require('../index')
const Schema = require('../database-schema/welcomeSchema')
const { MessageEmbed, Client, Intents, Discord } = require('discord.js')

        const allIntents = new Intents(32767);
        const client = new Client({intents: [ allIntents ]})


        client.on('guildMemberAdd', async (member, guild) => {
                Schema.findOne({ Guild: member.guild.id }, async (e, data) => {
                    if (!data) {
                        return console.log('No channel to send the message!')
                    }
                        

                    const channel = member.guild.channels.cache.get(data.Channel)
                    let role = member.guild.roles.cache.get(data.Role)

                    const embed = new MessageEmbed()
                        .setTitle('Welcome!')
                        .setColor('BLURPLE')
                        .setDescription(`Welcome to the server, ${member.tag}! I hope you will have a great time here.`)
                        .setTimestamp()

                    channel.send({ embeds: [embed] })


                    member.role.add()
                })
            })
        
           
        
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda