Skip to content

docs: add more examples #9252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/discord.js/src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,9 +1157,15 @@ class Guild extends AnonymousGuild {

/**
* Sets the guild's MFA level
* <info>An elevated MFA level requires guild moderators to have 2FA enabled.</info>
* @param {GuildMFALevel} level The MFA level
* @param {string} [reason] Reason for changing the guild's MFA level
* @returns {Promise<Guild>}
* @example
* // Set the MFA level of the guild to Elevated
* guild.setMFALevel(GuildMFALevel.Elevated)
* .then(guild => console.log("Set guild's MFA level to Elevated"))
* .catch(console.error);
*/
async setMFALevel(level, reason) {
await this.client.rest.post(Routes.guildMFA(this.id), {
Expand All @@ -1177,7 +1183,7 @@ class Guild extends AnonymousGuild {
* @example
* // Leave a guild
* guild.leave()
* .then(g => console.log(`Left the guild ${g}`))
* .then(guild => console.log(`Left the guild: ${guild.name}`))
* .catch(console.error);
*/
async leave() {
Expand Down
15 changes: 15 additions & 0 deletions packages/discord.js/src/structures/GuildMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ class GuildMember extends Base {
* Edits this member.
* @param {GuildMemberEditOptions} options The options to provide
* @returns {Promise<GuildMember>}
* @example
* // Deafen a guild member
* guildMember.edit({ deaf: true })
* .then(member => console.log(`Deafened ${member.nickname}`))
* .catch(console.log);
*/
edit(options) {
return this.guild.members.edit(this, options);
Expand All @@ -340,6 +345,11 @@ class GuildMember extends Base {
* @param {?string} nick The nickname for the guild member, or `null` if you want to reset their nickname
* @param {string} [reason] Reason for setting the nickname
* @returns {Promise<GuildMember>}
* @example
* // Remove a nickname for a guild member
* guildMember.setNickname(null, "No nicknames allowed!")
* .then(member => console.log(`Removed nickname for ${member.user.username}`))
* .catch(console.log);
*/
setNickname(nick, reason) {
return this.edit({ nick, reason });
Expand Down Expand Up @@ -396,6 +406,11 @@ class GuildMember extends Base {
* guildMember.disableCommunicationUntil(Date.now() + (5 * 60 * 1000), 'They deserved it')
* .then(console.log)
* .catch(console.error);
* @example
* // Remove the timeout of a guild member
* guildMember.disableCommunicationUntil(null)
* .then(member => `Removed timeout for ${member.displayName}`)
* .catch(console.error);
*/
disableCommunicationUntil(communicationDisabledUntil, reason) {
return this.edit({ communicationDisabledUntil, reason });
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,11 @@ class Message extends Base {
/**
* Fetches the Message this crosspost/reply/pin-add references, if available to the client
* @returns {Promise<Message>}
* @example
* // Fetch the reference of this message
* message.fetchReference()
* .then(reference => console.log(`Fetched the reference of this message: ${reference.content}`))
* .catch(console.error);
*/
async fetchReference() {
if (!this.reference) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
Expand Down
4 changes: 4 additions & 0 deletions packages/discord.js/src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class Role extends Base {
* @param {RoleResolvable} role Role to compare to this one
* @returns {number} Negative number if this role's position is lower (other role's is higher),
* positive number if this one is higher (other's is lower), 0 if equal
* * @example
* // Compare the position of a role to another
* const comparisation = comparedRole.comparePositionTo(roleToCompareTo)
* if (comparisation >= 1) console.log(`${comparedRole.name} is higher than ${roleToCompareTo.name}`)
*/
comparePositionTo(role) {
return this.guild.roles.comparePositions(this, role);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class InteractionResponses {
/**
* Collects a single modal submit interaction that passes the filter.
* The Promise will reject if the time expires.
* <info>Use the `showModal` method to show a modal to the user.</info>
* @param {AwaitModalSubmitOptions} options Options to pass to the internal collector
* @returns {Promise<ModalSubmitInteraction>}
* @example
Expand Down