Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
How do I invite someone to a guild in discord.js?

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.

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

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! ๐Ÿ˜„

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!