所以当一个新成员加入 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_PRESENCESGUILD_MEMBERS其中一个影响是您正在经历的,即不工作的 guildMemberAdd 事件.
好消息是您可以通过一个简单的步骤解决此问题.只需在
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_PRESENCESGUILD_MEMBERSOne 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.
这篇关于Discord.js 机器人欢迎会员,分配角色并向他们发送 DM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 discord.js 检测图像并响应Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
检查 Discord 服务器中是否存在用户 IDCheck if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
公会成员添加不起作用(discordjs)Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
使用 REPLIT 创建我的第一个机器人,但总是错误Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
如何为我的 Discord.js 机器人编写事件/命令处理程How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
如何从 Discord.js 中的用户名中查找用户 ID?How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)