mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
Backport: Guild#createChannel (#2145)
* Backport: Guild#createChannel * this should not return a buffer
This commit is contained in:
@@ -11,6 +11,7 @@ const Channel = require('../structures/Channel');
|
|||||||
const GuildMember = require('../structures/GuildMember');
|
const GuildMember = require('../structures/GuildMember');
|
||||||
const Emoji = require('../structures/Emoji');
|
const Emoji = require('../structures/Emoji');
|
||||||
const ReactionEmoji = require('../structures/ReactionEmoji');
|
const ReactionEmoji = require('../structures/ReactionEmoji');
|
||||||
|
const Role = require('../structures/Role');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them, e.g.
|
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them, e.g.
|
||||||
@@ -101,6 +102,27 @@ class ClientDataResolver {
|
|||||||
return guild.members.get(user.id) || null;
|
return guild.members.get(user.id) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data that can be resolved to a Role object. This can be:
|
||||||
|
* * A Role
|
||||||
|
* * A Snowflake
|
||||||
|
* @typedef {Role|Snowflake} RoleResolvable
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a RoleResolvable to a Role object.
|
||||||
|
* @param {GuildResolvable} guild The guild that this role is part of
|
||||||
|
* @param {RoleResolvable} role The role resolvable to resolve
|
||||||
|
* @returns {?Role}
|
||||||
|
*/
|
||||||
|
resolveRole(guild, role) {
|
||||||
|
if (role instanceof Role) return role;
|
||||||
|
guild = this.resolveGuild(guild);
|
||||||
|
if (!guild) return null;
|
||||||
|
if (typeof role === 'string') return guild.roles.get(role);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data that can be resolved to give a Channel object. This can be:
|
* Data that can be resolved to give a Channel object. This can be:
|
||||||
* * A Channel object
|
* * A Channel object
|
||||||
|
|||||||
@@ -253,7 +253,30 @@ class RESTMethods {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createChannel(guild, channelName, channelType, overwrites, reason) {
|
createChannel(guild, channelName, channelType, overwrites, reason) {
|
||||||
if (overwrites instanceof Collection) overwrites = overwrites.array();
|
if (overwrites instanceof Collection || overwrites instanceof Array) {
|
||||||
|
overwrites = overwrites.map(overwrite => {
|
||||||
|
let allow = overwrite.allow || overwrite._allowed;
|
||||||
|
let deny = overwrite.deny || overwrite._denied;
|
||||||
|
if (allow instanceof Array) allow = Permissions.resolve(allow);
|
||||||
|
if (deny instanceof Array) deny = Permissions.resolve(deny);
|
||||||
|
|
||||||
|
const role = this.client.resolver.resolveRole(this, overwrite.id);
|
||||||
|
if (role) {
|
||||||
|
overwrite.id = role.id;
|
||||||
|
overwrite.type = 'role';
|
||||||
|
} else {
|
||||||
|
overwrite.id = this.client.resolver.resolveUserID(overwrite.id);
|
||||||
|
overwrite.type = 'member';
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
allow,
|
||||||
|
deny,
|
||||||
|
type: overwrite.type,
|
||||||
|
id: overwrite.id,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
return this.rest.makeRequest('post', Endpoints.Guild(guild).channels, true, {
|
return this.rest.makeRequest('post', Endpoints.Guild(guild).channels, true, {
|
||||||
name: channelName,
|
name: channelName,
|
||||||
type: Constants.ChannelTypes[channelType.toUpperCase()],
|
type: Constants.ChannelTypes[channelType.toUpperCase()],
|
||||||
|
|||||||
@@ -873,11 +873,19 @@ class Guild {
|
|||||||
if (!this.client.user.bot) this.client.syncGuilds([this]);
|
if (!this.client.user.bot) this.client.syncGuilds([this]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used to overwrite permissions when creating a channel.
|
||||||
|
* @typedef {Object} ChannelCreationOverwrites
|
||||||
|
* @property {PermissionResolvable[]|number} [allow] The permissions to allow
|
||||||
|
* @property {PermissionResolvable[]|number} [deny] The permissions to deny
|
||||||
|
* @property {RoleResolvable|UserResolvable} id ID of the role or member this overwrite is for
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new channel in the guild.
|
* Creates a new channel in the guild.
|
||||||
* @param {string} name The name of the new channel
|
* @param {string} name The name of the new channel
|
||||||
* @param {string} type The type of the new channel, either `text` or `voice` or `category`
|
* @param {string} type The type of the new channel, either `text` or `voice` or `category`
|
||||||
* @param {Array<PermissionOverwrites|Object>} [overwrites] Permission overwrites to apply to the new channel
|
* @param {Array<PermissionOverwrites|ChannelCreationOverwrites>} [overwrites] Permission overwrites
|
||||||
* @param {string} [reason] Reason for creating this channel
|
* @param {string} [reason] Reason for creating this channel
|
||||||
* @returns {Promise<TextChannel|VoiceChannel>}
|
* @returns {Promise<TextChannel|VoiceChannel>}
|
||||||
* @example
|
* @example
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ class GuildChannel extends Channel {
|
|||||||
* @param {Role|Snowflake|UserResolvable} userOrRole The user or role to update
|
* @param {Role|Snowflake|UserResolvable} userOrRole The user or role to update
|
||||||
* @param {PermissionOverwriteOptions} options The configuration for the update
|
* @param {PermissionOverwriteOptions} options The configuration for the update
|
||||||
* @param {string} [reason] Reason for creating/editing this overwrite
|
* @param {string} [reason] Reason for creating/editing this overwrite
|
||||||
* @returns {Promise}
|
* @returns {Promise<GuildChannel>}
|
||||||
* @example
|
* @example
|
||||||
* // Overwrite permissions for a message author
|
* // Overwrite permissions for a message author
|
||||||
* message.channel.overwritePermissions(message.author, {
|
* message.channel.overwritePermissions(message.author, {
|
||||||
@@ -203,7 +203,7 @@ class GuildChannel extends Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.client.rest.methods.setChannelOverwrite(this, payload, reason);
|
return this.client.rest.methods.setChannelOverwrite(this, payload, reason).then(() => this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user