Search code examples
pythondiscord

Implementing discord bot joining logic via oauth: looking for solution on how to join my bot onto a guild


I am trying to add the logic onto my discord bot to add it to a guild however I can't figure out how to do this.

The first thing I tried was to create an algorithm to join a discord server with an oauth.

# an redrected url look like this https://www.example.com/?code=w1WuVLRAqsgBShI7iSlZXCTKlTXBKO&guild_id=1028775661361430648&permissions=71680
# an redrected url look like this https://www.example.com/?code=w1WuVLRAqsgBShI7iSlZXCTKlTXBKO&guild_id=1028775661361430648&permissions=71680
@app.get("/bot-added")
async def bot_added():
    code = request.args.get("code")
    g_id = request.args.get("guild_id")
    guild  = await bot.fetch_guild(g_id)
    g_invites = guild.invites()
    invites_q = []
            
    invites = asyncio.gather(invites_q)
    for invite in invites:
        if not isinstance(invite, HTTPException):
            # join server invite(invite)
            pass

While writing this code, I noticed that there are no function/method to join an invite.

While looking online for a solution I found a stackoverflow thread saying you could do a requests to the discord api directly. This solution seem to not be a great alternative due to the possibility of my bot being banned.

Is there a better way to do this?


Solution

  • After digging through the settings of the discord dashboard, I found out I had to disable the following option in order to add the bot to my server: REQUIRES OAUTH2 CODE GRANT