-
I am trying to understand the reasoning the ability to pass options to message.delete() was removed from v13, I just started to get my bot ready for once v13 is stable and noticed I will have to change all my code from:
This doesnt seem like a step in the right direction to me but I am also a novice. It also will cause me issues like this in 179 places throughout 56 files 😂 from causing me to constantly reach out of scope as well as making the code more difficult to skim and read. could anyone help me to understand why this change happened and/or if I could be implementing the change better than my above example? Edit, Ok so I just tried extending for the first time, should this be ok to do everywhere? Main file before Client is initialized: Structures.extend('Message', Message => { // they removed structures now in v13 as well, this will no longer work when stable comes out
class AdvancedMessage extends Message {
constructor(client, data, channel) {
super(client, data, channel);
}
delete2(options={}){
let timeUntilDelete = (!options) ? 0: (options.timeout) ? options.timeout: 0;
client.setTimeout(() => this.delete(), timeUntilDelete);
}
}
return AdvancedMessage;
}); Message.prototype.delete2 = function(options = {}){ // works with new changes (change logger to whatever your logging system is)
if (typeof options !== 'object')
return Promise.reject(new Error(`Invalid Object: Must be Timeout`, this.fileName, this.lineNumber));
const { timeout = 0 } = options;
if (timeout <= 0) {
return this.channel.messages.delete(this.id).then(() => this);
} else {
return new Promise(resolve => {
this.client.setTimeout(() => {
if(this.deleted){
resolve(Logger.warn(`Attempt to delete a message that has already been deleted.`));
} else {
resolve(this.delete());
}
}, timeout);
});
}
}; Where message.delete() was: message.delete2({timeout:5000}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Consistency with other methods and avoids possible issues such as the message being deleted before the timeout. |
Beta Was this translation helpful? Give feedback.
Consistency with other methods and avoids possible issues such as the message being deleted before the timeout.