1
1
'use strict' ;
2
2
3
+ const process = require ( 'node:process' ) ;
3
4
const { Collection } = require ( '@discordjs/collection' ) ;
4
5
const CachedManager = require ( './CachedManager' ) ;
5
6
const { TypeError, Error } = require ( '../errors' ) ;
6
7
const GuildBan = require ( '../structures/GuildBan' ) ;
7
8
const { GuildMember } = require ( '../structures/GuildMember' ) ;
8
9
10
+ let deprecationEmittedForDays = false ;
11
+
9
12
/**
10
13
* Manages API methods for GuildBans and stores their cache.
11
14
* @extends {CachedManager }
@@ -126,6 +129,9 @@ class GuildBanManager extends CachedManager {
126
129
* Options used to ban a user from a guild.
127
130
* @typedef {Object } BanOptions
128
131
* @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
129
135
* @property {string } [reason] The reason for the ban
130
136
*/
131
137
@@ -142,15 +148,30 @@ class GuildBanManager extends CachedManager {
142
148
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
143
149
* .catch(console.error);
144
150
*/
145
- async create ( user , options = { days : 0 } ) {
151
+ async create ( user , options = { } ) {
146
152
if ( typeof options !== 'object' ) throw new TypeError ( 'INVALID_TYPE' , 'options' , 'object' , true ) ;
147
153
const id = this . client . users . resolveId ( user ) ;
148
154
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
+
149
165
await this . client . api
150
166
. guilds ( this . guild . id )
151
167
. bans ( id )
152
168
. 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
+ } ,
154
175
reason : options . reason ,
155
176
} ) ;
156
177
if ( user instanceof GuildMember ) return user ;
0 commit comments