Giju Gijja
Giju Gijja

Reputation: 11

How can I create a discord server instant invite like using the discord API?

I know that there are many frameworks like discord.js to manage discord servers. but they are too complex for my need. I need to simply create discord instant invite like... I tried using the following link to get a code which aparently grants permission to create an instant invite, but I can't go beyond that... I dont want to use the discord.io Framework. I want to create an invite link with the code.

LINK:

https://discordapp.com/api/oauth2/authorize?client_id={clientId}&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fcallback&response_type=code&scope=guilds.join

I need a simple javascript solution, only to create a n instant invite link for my server to anyone who visits my website.

UPDATE:

I found that that I have to first Authorize my account/bot account with like this:

step 1: get authorization code with

https://discordapp.com/api/oauth2/authorize?client_id={clientId}&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fcallback&response_type=code&scope=guilds.join

step 2: exchange the code for a token with a POST request, here's how I tried it

//BUT I HAVE NO IDEA WHY THIS DOESN'T WORK

var client_id = '{CLIENT_ID}';
var client_secret = '{CLIENT_SECRET}';
var redirect_uri = 'http://localhost/callback';
var url = 'https://discordapp.com/api/oauth2/token';
var code = 'NVqrIAvYStyH7qMF6JjeVhbZWDO07u';

    var param = {
        'grant_type': 'authorization_code',
        'client_id': client_id,
        'client_secret': client_secret,
        'code': code,
        'redirect_uri': redirect_uri,
        'scope': 'guilds.join'
    };

    $.ajaxSetup({
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    });
    $.ajax({
        type: "POST",
        url: url,
        data: param,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(respose) {
            $('body').text(response);
        }
    });

after this, i'm supposed to get an authorization token to auto generate an invite WHICH I HAVE NO IDEA HOW TO DO....

Upvotes: 0

Views: 7113

Answers (1)

KYL3R
KYL3R

Reputation: 4073

Instant Invite -> Advanced Settings-> expire time : never.

link won't change.

Use that link instead of creating a new one for every visitor.

Upvotes: -1

Related Questions