Handle reaction roles for an unknown message gracefully
This commit is contained in:
parent
32782d0bfa
commit
301959f8fc
1 changed files with 13 additions and 1 deletions
|
@ -7,6 +7,7 @@ import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
||||||
import { Queue } from "../Queue";
|
import { Queue } from "../Queue";
|
||||||
import { ReactionRole } from "../data/entities/ReactionRole";
|
import { ReactionRole } from "../data/entities/ReactionRole";
|
||||||
import Timeout = NodeJS.Timeout;
|
import Timeout = NodeJS.Timeout;
|
||||||
|
import DiscordRESTError from "eris/lib/errors/DiscordRESTError"; // tslint:disable-line
|
||||||
|
|
||||||
type ReactionRolePair = [string, string, string?];
|
type ReactionRolePair = [string, string, string?];
|
||||||
|
|
||||||
|
@ -120,7 +121,18 @@ export class ReactionRolesPlugin extends ZeppelinPlugin<IReactionRolesPluginConf
|
||||||
*/
|
*/
|
||||||
async applyReactionRoleReactionsToMessage(channelId: string, messageId: string, reactionRoles: ReactionRole[]) {
|
async applyReactionRoleReactionsToMessage(channelId: string, messageId: string, reactionRoles: ReactionRole[]) {
|
||||||
const channel = this.guild.channels.get(channelId) as TextChannel;
|
const channel = this.guild.channels.get(channelId) as TextChannel;
|
||||||
const targetMessage = await channel.getMessage(messageId);
|
|
||||||
|
let targetMessage;
|
||||||
|
try {
|
||||||
|
targetMessage = await channel.getMessage(messageId);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof DiscordRESTError) {
|
||||||
|
logger.warn(`Reaction roles for unknown message ${messageId} in guild ${this.guild.name} (${this.guildId})`);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove old reactions, if any
|
// Remove old reactions, if any
|
||||||
const removeSleep = sleep(1250);
|
const removeSleep = sleep(1250);
|
||||||
|
|
Loading…
Add table
Reference in a new issue