I'm trying to get my discord bot to message a user with a link to join the guild, but I'm having trouble with who to send it to. Since they're not in the guild you can't message them.
if (!args[0]) return message.reply("Who would you like to invite? For example: funny#6942");
message.channel.createInvite({
unique: true,
maxUses: 1,
maxAge: 8 * 60 * 1000
})
.then(invite => {
var invited = args[0];
message.invited.send("https://discord.gg/" + invite.code);
//dm person with the invite code
});
I'm still somewhat new to Discord's JavaScript API.
You can look for that user in all cached users as in
client.users.cache.find((x) => {
x.tag == `${args[0]}`
}).send("https://discord.gg/" + invite.code); // This would return a GuildMember object and send the code to that person
There could be instances where the user is uncached, in those cases it's best to ask for an Id to the user and use
<Client>#user#fetch() on them although if your bot is small there's no need to worry! 😄