Event on 2 servers at the same time

Asked

Viewed 80 times

1

I am programming a bot for my Discord servers and wanted the Guild Member Add event to run on two servers at once.

const Discord = require('discord.js');
const { prefix } = require('../config.json');

module.exports = async (client, member) => {
    const channel = member.guild.channels.cache.find(channel => channel.name === "preferencial");

    let join = await new Discord.MessageEmbed()
    .setColor("#7c2ae8")
    .setTitle(`Boas-vindas, ${member.user.tag}`)
    .setDescription(`Peça ajuda em ${prefix}help`)
    .setImage("https://imgur.com/KiOx0Za.gif")
    .setTimestamp();
    channel.send(join);
}

How can I make the statement to work on another server? I am using Discord.js

2 answers

2

This event works for all servers where the bot is,an example of the code I’m using on my bot, and it works perfectly:

bot.on('guildMemberAdd', member => {
    var welcomeEmbed = new discord.MessageEmbed()
    .setColor('#0099ff')
    .setTitle(`**Welcome to the server ${member.user.username}**`)
    .setThumbnail(member.user.avatarURL())
    member.guild.channels.cache.get('Identificação do canal onde será enviada a mensagem aqui').send(welcomeEmbed)
});

2

This event works on every server the bot is on! If you want to set a different message for each server, one of the ways you can use is a banco de dados local, for this there are several packages available! One that I highly recommend for being easy to move is the Secure-db.

Example:

const db = require('secure-db');

db.set('id_do_servidor1-WELCOME', 'Seja bem-vindo');
db.set('id_do_servidor2-WELCOME', 'Olá, {membro}! Leia as regras e se divirta!');

bot.on('guildMemberAdd', member => {
    var welcomeEmbed = new discord.MessageEmbed()
    .setColor('#0099ff')
    .setDescription(db.get(`${member.guild.id}-WELCOME`));

    member.guild.channels.cache.get('ID DO CANAL').send(welcomeEmbed)
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.