mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
docs: improve examples (#2200)
* docs: improve examples another * remove conflict * some nuances * backport
This commit is contained in:
@@ -58,8 +58,8 @@ class Channel {
|
|||||||
* @example
|
* @example
|
||||||
* // Delete the channel
|
* // Delete the channel
|
||||||
* channel.delete()
|
* channel.delete()
|
||||||
* .then() // Success
|
* .then(console.log)
|
||||||
* .catch(console.error); // Log error
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
delete() {
|
delete() {
|
||||||
return this.client.rest.methods.deleteChannel(this);
|
return this.client.rest.methods.deleteChannel(this);
|
||||||
|
|||||||
@@ -486,6 +486,11 @@ class Guild {
|
|||||||
* @param {UserResolvable} [options.user] Only show entries involving this user
|
* @param {UserResolvable} [options.user] Only show entries involving this user
|
||||||
* @param {string|number} [options.type] Only show entries involving this action type
|
* @param {string|number} [options.type] Only show entries involving this action type
|
||||||
* @returns {Promise<GuildAuditLogs>}
|
* @returns {Promise<GuildAuditLogs>}
|
||||||
|
* @example
|
||||||
|
* // Output audit log entries
|
||||||
|
* guild.fetchAuditLogs()
|
||||||
|
* .then(audit => console.log(audit.entries))
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
fetchAuditLogs(options) {
|
fetchAuditLogs(options) {
|
||||||
return this.client.rest.methods.getGuildAuditLogs(this, options);
|
return this.client.rest.methods.getGuildAuditLogs(this, options);
|
||||||
@@ -514,6 +519,11 @@ class Guild {
|
|||||||
* @param {UserResolvable} user The user to fetch the member for
|
* @param {UserResolvable} user The user to fetch the member for
|
||||||
* @param {boolean} [cache=true] Insert the member into the members cache
|
* @param {boolean} [cache=true] Insert the member into the members cache
|
||||||
* @returns {Promise<GuildMember>}
|
* @returns {Promise<GuildMember>}
|
||||||
|
* @example
|
||||||
|
* // Fetch a guild member
|
||||||
|
* guild.fetchMember(message.author)
|
||||||
|
* .then(console.log)
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
fetchMember(user, cache = true) {
|
fetchMember(user, cache = true) {
|
||||||
user = this.client.resolver.resolveUser(user);
|
user = this.client.resolver.resolveUser(user);
|
||||||
|
|||||||
@@ -223,8 +223,8 @@ class GuildChannel extends Channel {
|
|||||||
* @returns {Promise<GuildChannel>}
|
* @returns {Promise<GuildChannel>}
|
||||||
* @example
|
* @example
|
||||||
* // Edit a channel
|
* // Edit a channel
|
||||||
* channel.edit({name: 'new-channel'})
|
* channel.edit({ name: 'new-channel' })
|
||||||
* .then(c => console.log(`Edited channel ${c}`))
|
* .then(console.log)
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
edit(data, reason) {
|
edit(data, reason) {
|
||||||
@@ -298,6 +298,11 @@ class GuildChannel extends Channel {
|
|||||||
* @param {boolean} [options.unique=false] Create a unique invite, or use an existing one with similar settings
|
* @param {boolean} [options.unique=false] Create a unique invite, or use an existing one with similar settings
|
||||||
* @param {string} [reason] Reason for creating the invite
|
* @param {string} [reason] Reason for creating the invite
|
||||||
* @returns {Promise<Invite>}
|
* @returns {Promise<Invite>}
|
||||||
|
* @example
|
||||||
|
* // Create an invite to a channel
|
||||||
|
* channel.createInvite()
|
||||||
|
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
createInvite(options = {}, reason) {
|
createInvite(options = {}, reason) {
|
||||||
return this.client.rest.methods.createChannelInvite(this, options, reason);
|
return this.client.rest.methods.createChannelInvite(this, options, reason);
|
||||||
|
|||||||
@@ -386,6 +386,16 @@ class GuildMember {
|
|||||||
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to apply
|
* @param {Collection<Snowflake, Role>|Role[]|Snowflake[]} roles The roles or role IDs to apply
|
||||||
* @param {string} [reason] Reason for applying the roles
|
* @param {string} [reason] Reason for applying the roles
|
||||||
* @returns {Promise<GuildMember>}
|
* @returns {Promise<GuildMember>}
|
||||||
|
* @example
|
||||||
|
* // Set the member's roles to a single role
|
||||||
|
* guildMember.setRoles(['391156570408615936'])
|
||||||
|
* .then(console.log)
|
||||||
|
* .catch(console.error);
|
||||||
|
* @example
|
||||||
|
* // Remove all the roles from a member
|
||||||
|
* guildMember.setRoles([])
|
||||||
|
* .then(member => console.log(`Member roles is now of ${member.roles.size} size`))
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
setRoles(roles, reason) {
|
setRoles(roles, reason) {
|
||||||
return this.edit({ roles }, reason);
|
return this.edit({ roles }, reason);
|
||||||
@@ -497,8 +507,10 @@ class GuildMember {
|
|||||||
* @param {string} [options.reason] Reason for banning
|
* @param {string} [options.reason] Reason for banning
|
||||||
* @returns {Promise<GuildMember>}
|
* @returns {Promise<GuildMember>}
|
||||||
* @example
|
* @example
|
||||||
* // ban a guild member
|
* // Ban a guild member
|
||||||
* guildMember.ban(7);
|
* guildMember.ban(7)
|
||||||
|
* .then(console.log)
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
ban(options) {
|
ban(options) {
|
||||||
return this.guild.ban(this, options);
|
return this.guild.ban(this, options);
|
||||||
|
|||||||
@@ -254,10 +254,8 @@ class Message {
|
|||||||
* @returns {ReactionCollector}
|
* @returns {ReactionCollector}
|
||||||
* @example
|
* @example
|
||||||
* // Create a reaction collector
|
* // Create a reaction collector
|
||||||
* const collector = message.createReactionCollector(
|
* const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID'
|
||||||
* (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID',
|
* const collector = message.createReactionCollector(filter, { time: 15000 });
|
||||||
* { time: 15000 }
|
|
||||||
* );
|
|
||||||
* collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
|
* collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
|
||||||
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
|
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
|
||||||
*/
|
*/
|
||||||
@@ -277,6 +275,12 @@ class Message {
|
|||||||
* @param {CollectorFilter} filter The filter function to use
|
* @param {CollectorFilter} filter The filter function to use
|
||||||
* @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector
|
* @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector
|
||||||
* @returns {Promise<Collection<string, MessageReaction>>}
|
* @returns {Promise<Collection<string, MessageReaction>>}
|
||||||
|
* @example
|
||||||
|
* // Create a reaction collector
|
||||||
|
* const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID'
|
||||||
|
* message.awaitReactions(filter, { time: 15000 })
|
||||||
|
* .then(collected => console.log(`Collected ${collected.size} reactions`))
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
awaitReactions(filter, options = {}) {
|
awaitReactions(filter, options = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class TextBasedChannel {
|
|||||||
* @returns {Promise<Collection<Snowflake, Message>>}
|
* @returns {Promise<Collection<Snowflake, Message>>}
|
||||||
* @example
|
* @example
|
||||||
* // Get messages
|
* // Get messages
|
||||||
* channel.fetchMessages({limit: 10})
|
* channel.fetchMessages({ limit: 10 })
|
||||||
* .then(messages => console.log(`Received ${messages.size} messages`))
|
* .then(messages => console.log(`Received ${messages.size} messages`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
@@ -303,7 +303,7 @@ class TextBasedChannel {
|
|||||||
* <info>It can take a few seconds for the client user to stop typing.</info>
|
* <info>It can take a few seconds for the client user to stop typing.</info>
|
||||||
* @param {boolean} [force=false] Whether or not to reset the call count and force the indicator to stop
|
* @param {boolean} [force=false] Whether or not to reset the call count and force the indicator to stop
|
||||||
* @example
|
* @example
|
||||||
* // Stop typing in a channel
|
* // Reduce the typing count by one and stop typing if it reached 0
|
||||||
* channel.stopTyping();
|
* channel.stopTyping();
|
||||||
* @example
|
* @example
|
||||||
* // Force typing to fully stop in a channel
|
* // Force typing to fully stop in a channel
|
||||||
@@ -357,10 +357,8 @@ class TextBasedChannel {
|
|||||||
* @returns {MessageCollector}
|
* @returns {MessageCollector}
|
||||||
* @example
|
* @example
|
||||||
* // Create a message collector
|
* // Create a message collector
|
||||||
* const collector = channel.createMessageCollector(
|
* const filter = m => m.content.includes('discord');
|
||||||
* m => m.content.includes('discord'),
|
* const collector = channel.createMessageCollector(filter, { time: 15000 });
|
||||||
* { time: 15000 }
|
|
||||||
* );
|
|
||||||
* collector.on('collect', m => console.log(`Collected ${m.content}`));
|
* collector.on('collect', m => console.log(`Collected ${m.content}`));
|
||||||
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
|
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
|
||||||
*/
|
*/
|
||||||
@@ -407,6 +405,11 @@ class TextBasedChannel {
|
|||||||
* @param {Collection<Snowflake, Message>|Message[]|number} messages Messages or number of messages to delete
|
* @param {Collection<Snowflake, Message>|Message[]|number} messages Messages or number of messages to delete
|
||||||
* @param {boolean} [filterOld=false] Filter messages to remove those which are older than two weeks automatically
|
* @param {boolean} [filterOld=false] Filter messages to remove those which are older than two weeks automatically
|
||||||
* @returns {Promise<Collection<Snowflake, Message>>} Deleted messages
|
* @returns {Promise<Collection<Snowflake, Message>>} Deleted messages
|
||||||
|
* @example
|
||||||
|
* // Bulk delete messages
|
||||||
|
* channel.bulkDelete(5)
|
||||||
|
* .then(messages => console.log(`Bulk deleted ${messages.size} messages`))
|
||||||
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
bulkDelete(messages, filterOld = false) {
|
bulkDelete(messages, filterOld = false) {
|
||||||
if (messages instanceof Array || messages instanceof Collection) {
|
if (messages instanceof Array || messages instanceof Collection) {
|
||||||
|
|||||||
Reference in New Issue
Block a user