并非每次都在guildMemberAdd上运行Discord.js

时间:2020-10-19 16:08:17

标签: javascript node.js discord.js

我不明白这有时是怎么回事,而有时它却不会增加人员数小时,并且会随机重新开始工作以解决此问题的任何想法?

编辑:同样,GUILD成员添加每次都不会每次都添加角色而确实运行。

    const Discord = require('discord.js');
    const bot = new Discord.Client();
    const token = '';
    
    bot.on('ready', () => {
        console.log('Bot is online!'); 
    })
    
    bot.on("guildMemberAdd", member => {
    var role = member.guild.roles.cache.find(role => role.name === "Member");
    setTimeout(function () {
        member.roles.add(role);
        // see if they have a role
        if (member.roles.cache.find(r => r.name !== "Member")) {
            member.roles.add(role);
            console.log(member.id);
        }
    }, 3000);
});


bot.login(token);

1 个答案:

答案 0 :(得分:0)

我不知道怎么做,因为我的代码没有做太多更改,但这一直没有问题。

const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'TOKEN_ID_HERE';

//checking to see if they subscribed
bot.on('ready', () => {
    console.log('Bot is online!');
})

bot.on('guildMemberAdd', member => {
    bot.channels.cache.get('CHANNEL_ID_HERE').send('<@' + member.id + '>');

    let role = member.guild.roles.cache.get("ROLE_ID_HERE");
    member.roles.add(role).then(console.log('DiscordID: ' + member.id));
});

bot.login(token);