Elitezen
Elitezen

Reputation: 6720

Get The Member Who Invited Bot

I'm trying to get the GuildMember object of whoever invited the bot using the guildCreate event.

const fetchedLogs = await message.guild.fetchAuditLogs({
   limit: 1,
   type: ''
})

Not sure if I'm on the right path, however, if I am, what argument do I pass for type?

Upvotes: 0

Views: 133

Answers (1)

secretlyrice
secretlyrice

Reputation: 305

here's the code I use to find the user who invited the bot, which is good enough for my purposes

bot.on('guildCreate', (guild) => {
  console.log(`event guildCreate: ${guild.name} ${guild.id}`);
  guild.fetchAuditLogs({ limit: 1, type: 28 }) // type 28 is "add bot"
    .then(audit => {
      let userID = audit.entries.first().executor.id;
      // do something here
    })
    .catch(console.error);
});

Upvotes: 1

Related Questions