Skip to content

Commit ca68fc3

Browse files
authoredSep 2, 2022
feat(GuildBanManager): Add deleteMessageSeconds (#8575)
1 parent a507ed9 commit ca68fc3

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed
 

‎src/managers/GuildBanManager.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
'use strict';
22

3+
const process = require('node:process');
34
const { Collection } = require('@discordjs/collection');
45
const CachedManager = require('./CachedManager');
56
const { TypeError, Error } = require('../errors');
67
const GuildBan = require('../structures/GuildBan');
78
const { GuildMember } = require('../structures/GuildMember');
89

10+
let deprecationEmittedForDays = false;
11+
912
/**
1013
* Manages API methods for GuildBans and stores their cache.
1114
* @extends {CachedManager}
@@ -126,6 +129,9 @@ class GuildBanManager extends CachedManager {
126129
* Options used to ban a user from a guild.
127130
* @typedef {Object} BanOptions
128131
* @property {number} [days=0] Number of days of messages to delete, must be between 0 and 7, inclusive
132+
* <warn>This property is deprecated. Use `deleteMessageSeconds` instead.</warn>
133+
* @property {number} [deleteMessageSeconds] Number of seconds of messages to delete,
134+
* must be between 0 and 604800 (7 days), inclusive
129135
* @property {string} [reason] The reason for the ban
130136
*/
131137

@@ -142,15 +148,30 @@ class GuildBanManager extends CachedManager {
142148
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
143149
* .catch(console.error);
144150
*/
145-
async create(user, options = { days: 0 }) {
151+
async create(user, options = {}) {
146152
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
147153
const id = this.client.users.resolveId(user);
148154
if (!id) throw new Error('BAN_RESOLVE_ID', true);
155+
156+
if (typeof options.days !== 'undefined' && !deprecationEmittedForDays) {
157+
process.emitWarning(
158+
'The days option for GuildBanManager#create() is deprecated. Use the deleteMessageSeconds option instead.',
159+
'DeprecationWarning',
160+
);
161+
162+
deprecationEmittedForDays = true;
163+
}
164+
149165
await this.client.api
150166
.guilds(this.guild.id)
151167
.bans(id)
152168
.put({
153-
data: { delete_message_days: options.days },
169+
data: {
170+
delete_message_seconds:
171+
typeof options.deleteMessageSeconds !== 'undefined'
172+
? options.deleteMessageSeconds
173+
: (options.days ?? 0) * 24 * 60 * 60,
174+
},
154175
reason: options.reason,
155176
});
156177
if (user instanceof GuildMember) return user;

‎src/managers/GuildMemberManager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class GuildMemberManager extends CachedManager {
379379
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
380380
* .catch(console.error);
381381
*/
382-
ban(user, options = { days: 0 }) {
382+
ban(user, options) {
383383
return this.guild.bans.create(user, options);
384384
}
385385

‎src/structures/GuildMember.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ class GuildMember extends Base {
378378
* @param {BanOptions} [options] Options for the ban
379379
* @returns {Promise<GuildMember>}
380380
* @example
381-
* // ban a guild member
382-
* guildMember.ban({ days: 7, reason: 'They deserved it' })
381+
* // Ban a guild member, deleting a week's worth of messages
382+
* guildMember.ban({ deleteMessageSeconds: 60 * 60 * 24 * 7, reason: 'They deserved it' })
383383
* .then(console.log)
384384
* .catch(console.error);
385385
*/

‎typings/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4034,7 +4034,9 @@ export interface AwaitReactionsOptions extends ReactionCollectorOptions {
40344034
}
40354035

40364036
export interface BanOptions {
4037+
/** @deprecated Use {@link deleteMessageSeconds} instead. */
40374038
days?: number;
4039+
deleteMessageSeconds?: number;
40384040
reason?: string;
40394041
}
40404042

0 commit comments

Comments
 (0)
Please sign in to comment.