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

158
Visualizações
How can my Discord Bot assign a Role to new Users?

First im new to Coding, that means i mostly Copie and Paste things.

To my problem: i do exactly things like in Videos, switch on "SERVER MEMBERS INTENT" in the Discord Dev portal and so on. But my Bot won't assign a Role after someone Joins my DC.

My code looks like a mess BUT! the function i wanted first that the Bot reply "pong" after i type !ping worked finaly after many hours of re-coding stuff.

here my code:

global.Discord = require('discord.js')
const { Client, Intents } = require('discord.js');
const { on } = require('events');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = "!";
const fs = require('fs');

const token = "my token";

client.commands = new Discord.Collection();
client.events = new Discord.Collection();

client.on('guildMemberAdd', guildMember =>{
    let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'anfänger');     

    guildMember.roles.add(welcomeRole);
    guildMember.guild.channels.cache.get('930264184510361670').send(`Welcome <${guildMember.user.id}> to out Server!`)
});

client.once("ready", () => {
    console.log(`Ready! Logged in as ${client.user.tag}! Im on ${client.guilds.cache.size} guild(s)!`)
    client.user.setActivity({type: "PLAYING", name: "Learning Code"})
});

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);
 
    client.commands.set(command.name, command);
}

client.on('messageCreate', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.split(' ').slice(1);
    const command = message.content.split(' ')[0].slice(prefix.length).toLowerCase();

    if(command === 'is'){
        client.commands.get('is').execute(message, args, Discord);
    }
});
 
client.login(token);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Aha! there it is you spelled guildMember as guildmember

client.on('guildMemberAdd', async guildMember => {
    var i = "930263943597928508";
    let role = guildMember.guild.roles.cache.find(r => r.id === i);
    guildmember.roles.add(role); //here replace guildmember with guildMember
})
about 4 years ago · Juan Pablo Isaza Relatório
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