discord.io icon indicating copy to clipboard operation
discord.io copied to clipboard

Trying to Direct Message New Member

Open DevDive opened this issue 7 years ago • 3 comments

Getting a "TypeError: Cannot read property 'id' of undefined" error when trying to direct message a new user.

Attempt 1: bot.on('guildMemberAdd', function (member) { //Confirm Member ID is correct (verified) console.dir(member.id); bot.sendMessage({ to: member.id; message: 'Test' }); });

Attempt 2: bot.on('guildMemberAdd', function (member) { //Confirm Member ID is correct (verified) console.dir(member.id); //Store the member ID as a variable, and pass that as the User ID userID = member.id; console.dir("User ID: "+userID); bot.sendMessage({ to: ''+userID+'', message: 'Test.' }); });

Error Message (for both attempts): TypeError: Cannot read property 'id' of undefined at C:\Users\Dheeraj\Documents\Programming\discordBot\node_modules\discord.io\lib\index.js:923:68 at C:\Users\Dheeraj\Documents\Programming\discordBot\node_modules\discord.io\lib\index.js:1464:13 at Gunzip.onEnd (zlib.js:227:5) at emitNone (events.js:91:20) at Gunzip.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickCallback (internal/process/next_tick.js:104:9)

Attempt 2 is a long shot, however we were able to message the Channel when using the Channel ID hard coded as a variable, so tried to replicate with the member ID

DevDive avatar Nov 07 '17 08:11 DevDive

I have seen recently where the guild_id does not make it into the "member" object on guildMemberRemove I wonder if this is related.

lc-101 avatar Nov 07 '17 18:11 lc-101

Oh, use the Github version. npm install izy521/discord.io

izy521 avatar Nov 07 '17 18:11 izy521

Apologies, we reinstalled NPM using the GitHub version as suggested, and it worked perfectly. Thank you.

DevDive avatar Nov 14 '17 07:11 DevDive