mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
backport: Guild#{fetchEmbed,setEmbed} (#2778)
* backport: Guild Embeds * fix: Added missing return * docs: Updated typings
This commit is contained in:
@@ -59,6 +59,13 @@ class RESTMethods {
|
||||
});
|
||||
}
|
||||
|
||||
fetchEmbed(guildID) {
|
||||
return this.rest.makeRequest('get', Endpoints.Guild(guildID).embed, true).then(data => ({
|
||||
enabled: data.enabled,
|
||||
channel: data.channel_id ? this.client.channels.get(data.channel_id) : null,
|
||||
}));
|
||||
}
|
||||
|
||||
sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split, code, reply } = {}, files = null) {
|
||||
return new Promise((resolve, reject) => { // eslint-disable-line complexity
|
||||
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
|
||||
@@ -853,6 +860,13 @@ class RESTMethods {
|
||||
);
|
||||
}
|
||||
|
||||
updateEmbed(guildID, embed, reason) {
|
||||
return this.rest.makeRequest('patch', Endpoints.Guild(guildID).embed, true, {
|
||||
enabled: embed.enabled,
|
||||
channel_id: this.client.resolver.resolveChannelID(embed.channel),
|
||||
}, undefined, reason);
|
||||
}
|
||||
|
||||
setRolePositions(guildID, roles) {
|
||||
return this.rest.makeRequest('patch', Endpoints.Guild(guildID).roles, true, roles).then(() =>
|
||||
this.client.actions.GuildRolesPositionUpdate.handle({
|
||||
|
||||
@@ -530,6 +530,26 @@ class Guild {
|
||||
return this.client.rest.methods.fetchVoiceRegions(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Guild Embed object
|
||||
* @typedef {Object} GuildEmbedData
|
||||
* @property {boolean} enabled Whether the embed is enabled
|
||||
* @property {?ChannelResolvable} channel The embed channel
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fetches the guild embed.
|
||||
* @returns {Promise<GuildEmbedData>}
|
||||
* @example
|
||||
* // Fetches the guild embed
|
||||
* guild.fetchEmbed()
|
||||
* .then(embed => console.log(`The embed is ${embed.enabled ? 'enabled' : 'disabled'}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchEmbed() {
|
||||
return this.client.rest.methods.fetchEmbed(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch audit logs for this guild.
|
||||
* @param {Object} [options={}] Options for fetching audit logs
|
||||
@@ -1025,6 +1045,17 @@ class Guild {
|
||||
return this.client.rest.methods.updateChannelPositions(this.id, channelPositions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the guild's embed.
|
||||
* @param {GuildEmbedData} embed The embed for the guild
|
||||
* @param {string} [reason] Reason for changing the guild's embed
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setEmbed(embed, reason) {
|
||||
return this.client.rest.methods.updateEmbed(this.id, embed, reason)
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new role in the guild with given information.
|
||||
* @param {RoleData} [data] The data to update the role with
|
||||
|
||||
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@@ -533,6 +533,7 @@ declare module 'discord.js' {
|
||||
public equals(guild: Guild): boolean;
|
||||
public fetchAuditLogs(options?: GuildAuditLogsFetchOptions): Promise<GuildAuditLogs>;
|
||||
public fetchBans(): Promise<Collection<Snowflake, User>>;
|
||||
public fetchEmbed(): Promise<GuildEmbedData>;
|
||||
public fetchInvites(): Promise<Collection<Snowflake, Invite>>;
|
||||
public fetchMember(user: UserResolvable, cache?: boolean): Promise<GuildMember>;
|
||||
public fetchMembers(query?: string, limit?: number): Promise<Guild>;
|
||||
@@ -547,6 +548,7 @@ declare module 'discord.js' {
|
||||
public setChannelPosition(channel: string | GuildChannel, position: number, relative?: boolean): Promise<Guild>;
|
||||
public setChannelPositions(channelPositions: ChannelPosition[]): Promise<Guild>;
|
||||
public setDefaultMessageNotification(defaultMessageNotifications: DefaultMessageNotifications, reason: string): Promise<Guild>;
|
||||
public setEmbed(embed: GuildEmbedData, reason?: string): Promise<Guild>;
|
||||
public setExcplicitContentFilter(explicitContentFilter: number, reason?: string): Promise<Guild>;
|
||||
public setIcon(icon: Base64Resolvable, reason?: string): Promise<Guild>;
|
||||
public setName(name: string, reason?: string): Promise<Guild>;
|
||||
@@ -1787,6 +1789,11 @@ declare module 'discord.js' {
|
||||
splash?: Base64Resolvable;
|
||||
};
|
||||
|
||||
type GuildEmbedData = {
|
||||
enabled: boolean;
|
||||
channel: ChannelResolvable;
|
||||
};
|
||||
|
||||
type GuildMemberEditData = {
|
||||
nick?: string;
|
||||
roles?: Collection<Snowflake, Role> | Role[] | Snowflake[];
|
||||
|
||||
Reference in New Issue
Block a user