mirror of
https://github.com/danbulant/discord.js
synced 2026-05-27 22:11:53 +00:00
refactor(APIRequest): utilize URLSearchParams (#3180)
* utilize URLSearchParams * options.query can be undefined/null * oops * remembered what I intended
This commit is contained in:
parent
c078682722
commit
5e9bd786d1
2 changed files with 15 additions and 7 deletions
|
|
@ -338,11 +338,15 @@ class Client extends BaseClient {
|
|||
* .then(link => console.log(`Generated bot invite link: ${link}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
generateInvite(permissions) {
|
||||
async generateInvite(permissions) {
|
||||
permissions = Permissions.resolve(permissions);
|
||||
return this.fetchApplication().then(application =>
|
||||
`https://discordapp.com/oauth2/authorize?client_id=${application.id}&permissions=${permissions}&scope=bot`
|
||||
);
|
||||
const application = await this.fetchApplication();
|
||||
const query = new URLSearchParams({
|
||||
client_id: application.id,
|
||||
permissions: permissions,
|
||||
scope: 'bot',
|
||||
});
|
||||
return `${this.options.http.api}${this.api.oauth2.authorize}?${query}`;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const querystring = require('querystring');
|
||||
const FormData = require('form-data');
|
||||
const https = require('https');
|
||||
const { browser, UserAgent } = require('../util/Constants');
|
||||
|
|
@ -16,8 +15,13 @@ class APIRequest {
|
|||
this.route = options.route;
|
||||
this.options = options;
|
||||
|
||||
const queryString = (querystring.stringify(options.query).match(/[^=&?]+=[^=&?]+/g) || []).join('&');
|
||||
this.path = `${path}${queryString ? `?${queryString}` : ''}`;
|
||||
let queryString = '';
|
||||
if (options.query) {
|
||||
// Filter out undefined query options
|
||||
const query = Object.entries(options.query).filter(([, value]) => typeof value !== 'undefined');
|
||||
queryString = new URLSearchParams(query).toString();
|
||||
}
|
||||
this.path = `${path}${queryString && `?${queryString}`}`;
|
||||
}
|
||||
|
||||
make() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue