mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
feat(Application): application flags (#5147)
Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
@@ -10,7 +10,6 @@ const ChannelManager = require('../managers/ChannelManager');
|
||||
const GuildManager = require('../managers/GuildManager');
|
||||
const UserManager = require('../managers/UserManager');
|
||||
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
||||
const ClientApplication = require('../structures/ClientApplication');
|
||||
const GuildPreview = require('../structures/GuildPreview');
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
const Invite = require('../structures/Invite');
|
||||
@@ -151,6 +150,12 @@ class Client extends BaseClient {
|
||||
*/
|
||||
this.user = null;
|
||||
|
||||
/**
|
||||
* The application of this bot
|
||||
* @type {?ClientApplication}
|
||||
*/
|
||||
this.application = null;
|
||||
|
||||
/**
|
||||
* Time at which the client was last regarded as being in the `READY` state
|
||||
* (each time the client disconnects and successfully reconnects, this will be overwritten)
|
||||
@@ -346,17 +351,6 @@ class Client extends BaseClient {
|
||||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the OAuth Application of this bot from Discord.
|
||||
* @returns {Promise<ClientApplication>}
|
||||
*/
|
||||
fetchApplication() {
|
||||
return this.api.oauth2
|
||||
.applications('@me')
|
||||
.get()
|
||||
.then(app => new ClientApplication(this, app));
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
||||
* @param {GuildResolvable} guild The guild to fetch the preview for
|
||||
@@ -383,24 +377,23 @@ class Client extends BaseClient {
|
||||
/**
|
||||
* Generates a link that can be used to invite the bot to a guild.
|
||||
* @param {InviteGenerationOptions} [options={}] Options for the invite
|
||||
* @returns {Promise<string>}
|
||||
* @returns {string}
|
||||
* @example
|
||||
* client.generateInvite({
|
||||
* const link = client.generateInvite({
|
||||
* permissions: [
|
||||
* Permissions.FLAGS.SEND_MESSAGES,
|
||||
* Permissions.FLAGS.MANAGE_GUILD,
|
||||
* Permissions.FLAGS.MENTION_EVERYONE,
|
||||
* ],
|
||||
* })
|
||||
* .then(link => console.log(`Generated bot invite link: ${link}`))
|
||||
* .catch(console.error);
|
||||
* });
|
||||
* console.log(`Generated bot invite link: ${link}`);
|
||||
*/
|
||||
async generateInvite(options = {}) {
|
||||
generateInvite(options = {}) {
|
||||
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
||||
if (!this.application) throw new Error('CLIENT_NOT_READY', 'generate an invite link');
|
||||
|
||||
const application = await this.fetchApplication();
|
||||
const query = new URLSearchParams({
|
||||
client_id: application.id,
|
||||
client_id: this.application.id,
|
||||
scope: 'bot',
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const ClientApplication = require('../../../structures/ClientApplication');
|
||||
let ClientUser;
|
||||
|
||||
module.exports = (client, { d: data }, shard) => {
|
||||
@@ -7,9 +8,8 @@ module.exports = (client, { d: data }, shard) => {
|
||||
client.user._patch(data.user);
|
||||
} else {
|
||||
if (!ClientUser) ClientUser = require('../../../structures/ClientUser');
|
||||
const clientUser = new ClientUser(client, data.user);
|
||||
client.user = clientUser;
|
||||
client.users.cache.set(clientUser.id, clientUser);
|
||||
client.user = new ClientUser(client, data.user);
|
||||
client.users.cache.set(client.user.id, client.user);
|
||||
}
|
||||
|
||||
for (const guild of data.guilds) {
|
||||
@@ -17,5 +17,11 @@ module.exports = (client, { d: data }, shard) => {
|
||||
client.guilds.add(guild);
|
||||
}
|
||||
|
||||
if (client.application) {
|
||||
client.application._patch(data.application);
|
||||
} else {
|
||||
client.application = new ClientApplication(client, data.application);
|
||||
}
|
||||
|
||||
shard.checkReady();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user