Discord.js 机器人欢迎会员,分配角色并向他们发送 DM

Discord.js Bot Welcomes Member, Assign a Role and send them a DM(Discord.js 机器人欢迎会员,分配角色并向他们发送 DM)
本文介绍了Discord.js 机器人欢迎会员,分配角色并向他们发送 DM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

所以当一个新成员加入 Guild [discord 服务器].Bot应该在某个频道(ID = 766716351007686696)中发送消息,向他们发送直接消息,然后添加角色(人豆).这是我现在拥有的代码,它不起作用,底部有错误

client.on('guildMemberAdd', member =>{const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")const channelwelcomeEmbed = new Discord.MessageEmbed().setColor('#ffd6d6').setTitle('欢迎!').setDescription(`${member} 刚刚加入不和谐!请务必阅读#rules!`).setTimestamp();channel.send(channelwelcomeEmbed);const dmwelcomeEmbed = new Discord.MessageEmbed().setColor('#ffd6d6').setTitle('欢迎!').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");//基本角色,每个人都明白if(!role6) return message.reply(找不到那个角色.")member.roles.add(role6);});

错误信息是;

 const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")^ReferenceError:消息未定义

解决方案

你的代码看起来很好,问题是事件没有被触发.那是因为不和谐关闭了特权意图".默认情况下.

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

  • GUILD_PRESENCES
  • GUILD_MEMBERS

其中一个影响是您正在经历的,即不工作的 guildMemberAdd 事件.

好消息是您可以通过一个简单的步骤解决此问题.只需在

如果您想了解更多信息

  • Discord.js 官方指南 - 网关意图
  • Discord 开发者文档 - 网关意图
  • 网关更新常见问题解答
  • Discord API Github - 第 1363 期 - 特权意图
  • Discord 博客 - Discord 上机器人的未来
  • 无我的 discord.js 公会成员事件正在发出,我的用户缓存基本上是空的,我的函数正在超时?

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);
});

Error Message is;

    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

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

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.

If you want to read more about it

  • 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 机器人欢迎会员,分配角色并向他们发送 DM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)