2017-07-08 68 views
0

您好我想讓殭屍工具發送直接/私人消息給加入服務器的新用戶。它能夠在一個頻道上發佈歡迎消息,但它會一直拋出直接消息的錯誤。Discord.js - 發送私人消息的直接消息,以歡迎加入服務器的新用戶

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

bot.on('ready',() => { 
    console.log('I am ready!'); 
}); 

bot.on('guildMemberAdd', member => { 
     member.guild.defaultChannel.send(`Welcome to the server, ${member}!`); 
     console.log(`${member.user.username} has joined`); 
}); 

bot.login('TOKEN_HERE'); 
+0

有什麼錯誤? –

+0

我正在嘗試幾種方法,但其中大多數給我一個函數錯誤。我最後使用了這個:member.sendMessage(message.author,「Hello!」);並給出了一個未定義的錯誤。 – GodIsGhost

回答

0

Member對象具有與通道類似的發送方法。

注意的sendMessage已被棄用

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

bot.on('guildMemberAdd', member => { 
    member.send("Welcome to the server!"); 
}); 

bot.login('TOKEN_HERE'); 
+0

非常感謝! – GodIsGhost

相關問題