mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
Fix for GroupDMChannel#addUser and added removeUser, setName and edit (#1576)
* fixed GroupDMChannel#addUser, added setName and removeUser and changed every `the Group DM`to `this Group DM`, for consistency * added edit method * delete method comes already with the Channel class * brackets * removed empty line
This commit is contained in:
@@ -47,7 +47,7 @@ class GroupDMChannel extends Channel {
|
|||||||
this.name = data.name;
|
this.name = data.name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hash of the Group DM icon.
|
* A hash of this Group DM icon
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.icon = data.icon;
|
this.icon = data.icon;
|
||||||
@@ -125,20 +125,58 @@ class GroupDMChannel extends Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a user to the DM
|
* Edits this Group DM.
|
||||||
* @param {UserResolvable|string} accessTokenOrUser Access token or user resolvable
|
* @param {Object} data New data for this Group DM
|
||||||
* @param {string} [nick] Permanent nickname to give the user (only available if a bot is creating the DM)
|
* @param {string} [reason] Reason for editing this Group DM
|
||||||
* @returns {Promise<GroupDMChannel>}
|
* @returns {Promise<GroupDMChannel>}
|
||||||
*/
|
*/
|
||||||
addUser(accessTokenOrUser, nick) {
|
edit(data, reason) {
|
||||||
const id = this.client.resolver.resolveUserID(accessTokenOrUser);
|
return this.client.api.channels[this.id].patch({
|
||||||
|
data: {
|
||||||
|
name: (data.name || this.name).trim(),
|
||||||
|
},
|
||||||
|
reason,
|
||||||
|
}).then(() => this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new name for this Group DM.
|
||||||
|
* @param {string} name New name for this Group DM
|
||||||
|
* @returns {Promise<GroupDMChannel>}
|
||||||
|
*/
|
||||||
|
setName(name) {
|
||||||
|
return this.edit({ name });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an user to this Group DM.
|
||||||
|
* @param {Object} options Options for this method
|
||||||
|
* @param {UserResolveable} options.user User to add to this Group DM
|
||||||
|
* @param {string} [options.accessToken] Access token to use to add the user to this Group DM
|
||||||
|
* (only available under a bot account)
|
||||||
|
* @param {string} [options.nick] Permanent nickname to give the user (only available under a bot account)
|
||||||
|
* @returns {Promise<GroupDMChannel>}
|
||||||
|
*/
|
||||||
|
addUser({ user, accessToken, nick }) {
|
||||||
|
const id = this.client.resolver.resolveUserID(user);
|
||||||
const data = this.client.user.bot ?
|
const data = this.client.user.bot ?
|
||||||
{ nick, access_token: accessTokenOrUser } :
|
{ nick, access_token: accessToken } :
|
||||||
{ recipient: id };
|
{ recipient: id };
|
||||||
return this.client.api.channels[this.id].recipients[id].put({ data })
|
return this.client.api.channels[this.id].recipients[id].put({ data })
|
||||||
.then(() => this);
|
.then(() => this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an user from this Group DM.
|
||||||
|
* @param {UserResolveable} user User to remove
|
||||||
|
* @returns {Promise<GroupDMChannel>}
|
||||||
|
*/
|
||||||
|
removeUser(user) {
|
||||||
|
const id = this.client.resolver.resolveUserID(user);
|
||||||
|
return this.client.api.channels[this.id].recipients[id].delete()
|
||||||
|
.then(() => this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When concatenated with a string, this automatically concatenates the channel's name instead of the Channel object.
|
* When concatenated with a string, this automatically concatenates the channel's name instead of the Channel object.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
|
|||||||
Reference in New Issue
Block a user