Skip to content

Commit

Permalink
✨ immediately update message after edit()
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico105 committed Jun 16, 2021
1 parent c3c6c1d commit b984859
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ client.on('message', (message) => {
newWinnerCount: 3,
newPrize: 'New Prize!'
}).then(() => {
// Here, we can calculate the time after which we are sure that the lib will update the giveaway
const numberOfSecondsMax = client.giveawaysManager.options.updateCountdownEvery / 1000;
message.channel.send('Success! Giveaway will update in less than ' + numberOfSecondsMax + ' seconds.');
message.channel.send('Success! Giveaway updated!');
}).catch((err) => {
message.channel.send(`An error has occurred, please check and try again.\n\`${err}\``);
});
Expand Down
4 changes: 1 addition & 3 deletions examples/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ client.on('message', (message) => {
newWinnerCount: 3,
newPrize: 'New Prize!'
}).then(() => {
// Here, we can calculate the time after which we are sure that the lib will update the giveaway
const numberOfSecondsMax = client.giveawaysManager.options.updateCountdownEvery / 1000;
message.channel.send('Success! Giveaway will update in less than ' + numberOfSecondsMax + ' seconds.');
message.channel.send('Success! Giveaway updated!');
}).catch((err) => {
message.channel.send(`An error has occurred, please check and try again.\n\`${err}\``);
});
Expand Down
8 changes: 7 additions & 1 deletion src/Giveaway.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class Giveaway extends EventEmitter {
if (!this.channel) return reject('Unable to get the channel of the giveaway with message ID ' + this.messageID + '.');
await this.fetchMessage().catch(() => {});
if (!this.message) return reject('Unable to fetch message with ID ' + this.messageID + '.');

// Update data
if (Number.isInteger(options.newWinnerCount) && options.newWinnerCount > 0) this.winnerCount = options.newWinnerCount;
if (typeof options.newPrize === 'string') this.prize = options.newPrize;
Expand All @@ -485,8 +486,13 @@ class Giveaway extends EventEmitter {
if (typeof options.newThumbnail === 'string') this.thumbnail = options.newThumbnail;
if (Array.isArray(options.newBonusEntries)) this.options.bonusEntries = options.newBonusEntries.filter((elem) => typeof elem === 'object');
if (options.newExtraData) this.extraData = options.newExtraData;
// Call the db method

await this.manager.editGiveaway(this.messageID, this.data);
if (this.remainingTime <= 0) this.manager.end(this.messageID).catch(() => {});
else {
const embed = this.manager.generateMainEmbed(this);
this.message.edit(this.messages.giveaway, { embed }).catch(() => {});
}
resolve(this);
});
}
Expand Down

0 comments on commit b984859

Please sign in to comment.