mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
Client method examples. (#2264)
* Client method examples.
* Consistency
* As per hydras request 🙇
* Thanks kya
This commit is contained in:
@@ -287,6 +287,11 @@ class Client extends BaseClient {
|
|||||||
* Obtains an invite from Discord.
|
* Obtains an invite from Discord.
|
||||||
* @param {InviteResolvable} invite Invite code or URL
|
* @param {InviteResolvable} invite Invite code or URL
|
||||||
* @returns {Promise<Invite>}
|
* @returns {Promise<Invite>}
|
||||||
|
* @example
|
||||||
|
* client.fetchInvite('https://discord.gg/bRCvFy9')
|
||||||
|
* .then(invite => {
|
||||||
|
* console.log(`Obtained invite with code: ${invite.code}`);
|
||||||
|
* }).catch(console.error);
|
||||||
*/
|
*/
|
||||||
fetchInvite(invite) {
|
fetchInvite(invite) {
|
||||||
const code = DataResolver.resolveInviteCode(invite);
|
const code = DataResolver.resolveInviteCode(invite);
|
||||||
@@ -299,6 +304,11 @@ class Client extends BaseClient {
|
|||||||
* @param {Snowflake} id ID of the webhook
|
* @param {Snowflake} id ID of the webhook
|
||||||
* @param {string} [token] Token for the webhook
|
* @param {string} [token] Token for the webhook
|
||||||
* @returns {Promise<Webhook>}
|
* @returns {Promise<Webhook>}
|
||||||
|
* @example
|
||||||
|
* client.fetchWebhook('id', 'token')
|
||||||
|
* .then(webhook => {
|
||||||
|
* console.log(`Obtained webhook with name: ${webhook.name}`);
|
||||||
|
* }).catch(console.error);
|
||||||
*/
|
*/
|
||||||
fetchWebhook(id, token) {
|
fetchWebhook(id, token) {
|
||||||
return this.api.webhooks(id, token).get().then(data => new Webhook(this, data));
|
return this.api.webhooks(id, token).get().then(data => new Webhook(this, data));
|
||||||
@@ -307,6 +317,11 @@ class Client extends BaseClient {
|
|||||||
/**
|
/**
|
||||||
* Obtains the available voice regions from Discord.
|
* Obtains the available voice regions from Discord.
|
||||||
* @returns {Collection<string, VoiceRegion>}
|
* @returns {Collection<string, VoiceRegion>}
|
||||||
|
* @example
|
||||||
|
* client.fetchVoiceRegions()
|
||||||
|
* .then(regions => {
|
||||||
|
* console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`);
|
||||||
|
* }).catch(console.error);
|
||||||
*/
|
*/
|
||||||
fetchVoiceRegions() {
|
fetchVoiceRegions() {
|
||||||
return this.api.voice.regions.get().then(res => {
|
return this.api.voice.regions.get().then(res => {
|
||||||
@@ -323,6 +338,10 @@ class Client extends BaseClient {
|
|||||||
* will be removed from the caches. The default is based on {@link ClientOptions#messageCacheLifetime}
|
* will be removed from the caches. The default is based on {@link ClientOptions#messageCacheLifetime}
|
||||||
* @returns {number} Amount of messages that were removed from the caches,
|
* @returns {number} Amount of messages that were removed from the caches,
|
||||||
* or -1 if the message cache lifetime is unlimited
|
* or -1 if the message cache lifetime is unlimited
|
||||||
|
* @example
|
||||||
|
* // Remove all messages older than 1800 seconds from the messages cache
|
||||||
|
* const amount = client.sweepMessages(1800);
|
||||||
|
* console.log(`Successfully removed ${amount} messages from the cache.`);
|
||||||
*/
|
*/
|
||||||
sweepMessages(lifetime = this.options.messageCacheLifetime) {
|
sweepMessages(lifetime = this.options.messageCacheLifetime) {
|
||||||
if (typeof lifetime !== 'number' || isNaN(lifetime)) {
|
if (typeof lifetime !== 'number' || isNaN(lifetime)) {
|
||||||
@@ -359,6 +378,11 @@ class Client extends BaseClient {
|
|||||||
* Obtains the OAuth Application of the bot from Discord.
|
* Obtains the OAuth Application of the bot from Discord.
|
||||||
* @param {Snowflake} [id='@me'] ID of application to fetch
|
* @param {Snowflake} [id='@me'] ID of application to fetch
|
||||||
* @returns {Promise<ClientApplication>}
|
* @returns {Promise<ClientApplication>}
|
||||||
|
* @example
|
||||||
|
* client.fetchApplication('id')
|
||||||
|
* .then(application => {
|
||||||
|
* console.log(`Obtained application with name: ${application.name}`);
|
||||||
|
* }).catch(console.error);
|
||||||
*/
|
*/
|
||||||
fetchApplication(id = '@me') {
|
fetchApplication(id = '@me') {
|
||||||
return this.api.oauth2.applications(id).get()
|
return this.api.oauth2.applications(id).get()
|
||||||
@@ -374,7 +398,7 @@ class Client extends BaseClient {
|
|||||||
* client.generateInvite(['SEND_MESSAGES', 'MANAGE_GUILD', 'MENTION_EVERYONE'])
|
* client.generateInvite(['SEND_MESSAGES', 'MANAGE_GUILD', 'MENTION_EVERYONE'])
|
||||||
* .then(link => {
|
* .then(link => {
|
||||||
* console.log(`Generated bot invite link: ${link}`);
|
* console.log(`Generated bot invite link: ${link}`);
|
||||||
* });
|
* }).catch(console.error);
|
||||||
*/
|
*/
|
||||||
generateInvite(permissions) {
|
generateInvite(permissions) {
|
||||||
if (permissions) {
|
if (permissions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user