Discord.js Bot欢迎成员,分配角色并向他们发送DM [英] Discord.js Bot Welcomes Member, Assign a Role and send them a DM

查看:100
本文介绍了Discord.js Bot欢迎成员,分配角色并向他们发送DM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,当新成员加入Guild [不和谐服务器]时.机器人应在某个频道(ID = 766716351007686696)中发送一条消息,向他们发送一条直接消息,然后添加一个角色(人类Bean).这是我现在拥有的代码,它无法正常工作,底部错误

So When A New Member Joins The Guild [the discord server]. The Bot Should Send A Message In a certain Channel (ID = 766716351007686696), Send Them A Direct Message, And Then Add A Role (Human Bean). This Is The code I Have Now and it isn't working, error at the bottom

client.on('guildMemberAdd', member =>{
    const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")
    const channelwelcomeEmbed = new Discord.MessageEmbed()
        .setColor('#ffd6d6')
        .setTitle('Welcome!')
        .setDescription(`${member} just joined the discord! Make sure to read #rules!`)
        .setTimestamp();
    channel.send(channelwelcomeEmbed);
    const dmwelcomeEmbed = new Discord.MessageEmbed()
        .setColor('#ffd6d6')
        .setTitle('Welcome!')
        .setDescription("For Help Using @Pro Bot#7903, Send The Command `!help` In Server")
        .setTimestamp();
    member.send(dmwelcomeEmbed);
    let role6 = message.guild.roles.cache.find(role => role.name == "Human Bean"); //BASIC ROLE, EVERYONE GETS IT
    if(!role6) return message.reply("Couldn't find that Role .")
    member.roles.add(role6);
});

错误消息是;

    const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")
                    ^

ReferenceError: message is not defined

推荐答案

您的代码看起来不错,问题在于未触发该事件.那是因为不和谐将特权意图"关闭了.默认情况下.

Your code looks fine, the problem is that the event isn't triggered. Thats because discord turned off "privileged intents" by default.

某些意图被定义为特权".由于数据的敏感性.这些意图是:

Some intents are defined as "Privileged" due to the sensitive nature of the data. Those intents are:

  • GUILD_PRESENCES
  • GUILD_MEMBERS
  • GUILD_PRESENCES
  • GUILD_MEMBERS

影响之一就是您正在体验的是不起作用的guildMemberAdd事件.

One effect of that is what you are experiencing, the not working guildMemberAdd event.

好消息是,您可以通过一个简单的步骤来解决此问题.只需在 discord开发人员门户网站中启用 Privileged Gateway Intents .很好.

The good news is that you can fix this with one easy step. Simply enable Privileged Gateway Intents in the discord developer portal and it should work just fine.

  • Discord.js Official Guide - Gateway Intents
  • Discord Developer Documentation - Gateway Intents
  • Gateway Update FAQ
  • Discord API Github - Issue 1363 - Priviledged Intents
  • Discord Blog - The Future of Bots on Discord
  • None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?

这篇关于Discord.js Bot欢迎成员,分配角色并向他们发送DM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆