0

I'd like to get all the invite links from every server that the bot is in but is it even possible?

4
  • You can get invites with typing await guild.invites() Apr 17, 2021 at 15:52
  • It sends me "[]" and nothing else...
    – User456
    Apr 17, 2021 at 16:14
  • You have to get an invite for a channel, do not know if the bot will be able to do that for every guild
    – Dominik
    Apr 17, 2021 at 16:16
  • It can do it if the bot has the permissions
    – Ceres
    Apr 18, 2021 at 3:15

1 Answer 1

1

You would have to iterate over bot.guilds, choose a channel from guild.text_channels, and call .create_invite() on that channel. Here is an example:

invites = []

for guild in bot.guilds:
    for c in guild.text_channels:
        if c.permissions_for(guild.me).create_instant_invite:  # make sure the bot can actually create an invite
            invite = await c.create_invite()
            invites.append(invite)
            break  # stop iterating over guild.text_channels, since you only need one invite per guild

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.