mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
Internal API Request Rewrite (#1490)
* start rewrite * converted guilds * more changes * convert GuildMember * convert User and remove friend methods which kill people * convert more stuff * even more stuff * make things nicer * speed and fixes and stuff * almost finished * fix * Update Client.js * uwu * Update RESTMethods.js * message editing * fix router * fix issue with references * message delete reason * move message sending * fix dm * message splitting * NO MORE REST METHODS * Update Client.js * Update WebhookClient.js * remove all those endpoints from the constants * Update ClientUser.js * Update ClientUser.js * fixes * Update ClientUser.js * complaiancy * all sort of fixes * merge master (#1) * Fix Permissions now that member is deprecated (#1491) * removing more deprecation leftovers (#1492) * Fix MessageCollectors * Fix awaitMessages (#1493) * Fix MessageCollector#cleanup * Fix MessageCollector#postCheck * Add max option back for safety * Update Invite.js (#1496) * guild setPosition missing docs (#1498) * missing docs * update return docs * indent * switched .invites for the apirouter and invite.js * make multiple options an object * Update ClientUser.js * fix nicks * Update WebhookClient.js
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const Channel = require('./Channel');
|
||||
const Role = require('./Role');
|
||||
const Invite = require('./Invite');
|
||||
const PermissionOverwrites = require('./PermissionOverwrites');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Collection = require('../util/Collection');
|
||||
@@ -138,7 +139,8 @@ class GuildChannel extends Channel {
|
||||
* Overwrites the permissions for a user or role in this channel.
|
||||
* @param {RoleResolvable|UserResolvable} userOrRole The user or role to update
|
||||
* @param {PermissionOverwriteOptions} options The configuration for the update
|
||||
* @returns {Promise}
|
||||
* @param {string} [reason] Reason for creating/editing this overwrite
|
||||
* @returns {Promise<GuildChannel>}
|
||||
* @example
|
||||
* // Overwrite permissions for a message author
|
||||
* message.channel.overwritePermissions(message.author, {
|
||||
@@ -147,7 +149,7 @@ class GuildChannel extends Channel {
|
||||
* .then(() => console.log('Done!'))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
overwritePermissions(userOrRole, options) {
|
||||
overwritePermissions(userOrRole, options, reason) {
|
||||
const payload = {
|
||||
allow: 0,
|
||||
deny: 0,
|
||||
@@ -186,7 +188,9 @@ class GuildChannel extends Channel {
|
||||
}
|
||||
}
|
||||
|
||||
return this.client.rest.methods.setChannelOverwrite(this, payload);
|
||||
return this.client.api.channels(this.id).permissions(payload.id)
|
||||
.put({ data: payload, reason })
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,6 +206,7 @@ class GuildChannel extends Channel {
|
||||
/**
|
||||
* Edits the channel.
|
||||
* @param {ChannelData} data The new data for the channel
|
||||
* @param {string} [reason] Reason for editing this channel
|
||||
* @returns {Promise<GuildChannel>}
|
||||
* @example
|
||||
* // Edit a channel
|
||||
@@ -209,8 +214,17 @@ class GuildChannel extends Channel {
|
||||
* .then(c => console.log(`Edited channel ${c}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(data) {
|
||||
return this.client.rest.methods.updateChannel(this, data);
|
||||
edit(data, reason) {
|
||||
return this.client.api.channels(this.id).patch({
|
||||
data: {
|
||||
name: (data.name || this.name).trim(),
|
||||
topic: data.topic || this.topic,
|
||||
position: data.position || this.position,
|
||||
bitrate: data.bitrate || this.bitrate,
|
||||
user_limit: data.userLimit || this.userLimit,
|
||||
},
|
||||
reason,
|
||||
}).then(newData => this.client.actions.ChannelUpdate.handle(newData).updated);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +267,7 @@ class GuildChannel extends Channel {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
setTopic(topic) {
|
||||
return this.client.rest.methods.updateChannel(this, { topic });
|
||||
return this.edit({ topic });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,10 +283,14 @@ class GuildChannel extends Channel {
|
||||
* kicked after 24 hours if they have not yet received a role
|
||||
* @param {number} [options.maxAge=86400] How long the invite should last (in seconds, 0 for forever)
|
||||
* @param {number} [options.maxUses=0] Maximum number of uses
|
||||
* @param {string} [reason] Reason for creating this
|
||||
* @returns {Promise<Invite>}
|
||||
*/
|
||||
createInvite(options = {}) {
|
||||
return this.client.rest.methods.createChannelInvite(this, options);
|
||||
createInvite({ temporary = false, maxAge = 86400, maxUses = 0 }, reason) {
|
||||
return this.client.api.channels(this.id).invites.post({ data: {
|
||||
temporary, max_age: maxAge, max_uses: maxUses,
|
||||
}, reason })
|
||||
.then(invite => new Invite(this.client, invite));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,6 +340,20 @@ class GuildChannel extends Channel {
|
||||
this.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this channel.
|
||||
* @param {string} [reason] Reason for deleting this channel
|
||||
* @returns {Promise<GuildChannel>}
|
||||
* @example
|
||||
* // Delete the channel
|
||||
* channel.delete('making room for new channels')
|
||||
* .then() // Success
|
||||
* .catch(console.error); // Log error
|
||||
*/
|
||||
delete(reason) {
|
||||
return this.client.api.channels(this.id).delete({ reason }).then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
* When concatenated with a string, this automatically returns the channel's mention instead of the Channel object.
|
||||
* @returns {string}
|
||||
|
||||
Reference in New Issue
Block a user