紅糖糍粑
2023-07-20 14:46:52
所以當(dāng)新成員加入Guild[不和諧服務(wù)器]時(shí)。機(jī)器人應(yīng)該在某個(gè)頻道(ID = 766716351007686696)發(fā)送消息,向他們發(fā)送直接消息,然后添加角色(Human Bean)。這是我現(xiàn)在擁有的代碼,它不起作用,底部有錯(cuò)誤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);});錯(cuò)誤消息是; const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696") ^ReferenceError: message is not defined
2 回答

慕虎7371278
TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊
您的代碼看起來不錯(cuò),問題是未觸發(fā)該事件。那是因?yàn)椴缓椭C默認(rèn)關(guān)閉了“特權(quán)意圖”。
由于數(shù)據(jù)的敏感性,某些意圖被定義為“特權(quán)”。這些意圖是:
GUILD_PRESENCES
GUILD_MEMBERS
其影響之一就是您正在經(jīng)歷的情況,即不起作用的guildMemberAdd
事件。
好消息是您只需一個(gè)簡(jiǎn)單的步驟即可解決此問題。只需在Discord 開發(fā)人員門戶中啟用特權(quán)網(wǎng)關(guān)意圖,它就應(yīng)該可以正常工作。

慕標(biāo)琳琳
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊
使固定:const channel = member.guild.channels.cache.get('CHANNEL ID')
您需要使用member
而不是message
. 因?yàn)?code>guildMemberAdd函數(shù)使用member
.
client.on('guildMemberAdd', member => {
添加回答
舉報(bào)
0/150
提交
取消