Así que estaba creando un sistema de bienvenida en mi bot de discordia y encontré el problema de que mi código no funciona (no responde) pero no hay ningún error.
Así que hice un comando para configurar el canal de bienvenida. Funciona.
También configuré Schema (yo uso mongoDB) donde guardaré guildId, ChannelId y RoleID. --Trabajar
Luego tengo el archivo: welcomer.js que en realidad necesita enviar el mensaje cuando el usuario se une, pero no, tampoco tengo ningún error en la consola:
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) } } }bienvenidoEsquema.js:
const mongoose = require('mongoose') const Schema = new mongoose.Schema({ Guild: String, Channel: String, Role: String, }) module.exports = mongoose.model('welcome-channel', Schema)bienvenido.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() }) })