make return value for role non optional, instead throws on error
This commit is contained in:
parent
ef39c6315d
commit
a50ac1716f
@ -34,11 +34,16 @@ export default class RoleController {
|
||||
return this.removeRoleFromUser(guildMember, roleToRemove, guild.id, requestId)
|
||||
}
|
||||
|
||||
public async getAnnouncementRoleForGuild(guild: Guild, requestId: string): Promise<Maybe<Role>> {
|
||||
public async getAnnouncementRoleForGuild(guild: Guild, requestId: string): Promise<Role> {
|
||||
const mediaRole = this.getAnnounceRoleIdForGuild(guild.id)
|
||||
return guild.roles.fetch()
|
||||
const announcement_role = await guild.roles.fetch()
|
||||
.then(fetchedRoles => fetchedRoles.find(role => role.id === mediaRole))
|
||||
.catch(error => { logger.error(`Could not find announcement_role with id ${config.bot.announcement_role}. Error: ${error}`, { requestId, guildId: guild.id }) })
|
||||
.catch(error => {
|
||||
logger.error(`Could not find announcement_role with id ${config.bot.announcement_role}. Error: ${error}`, { requestId, guildId: guild.id })
|
||||
throw error
|
||||
})
|
||||
if (!announcement_role) throw new Error(`Could not find announcement_role with id ${config.bot.announcement_role}.`)
|
||||
return announcement_role
|
||||
}
|
||||
|
||||
public async assignAnnouncementRolesFromReaction(guild: Guild, reaction: MessageReaction, requestId: string) {
|
||||
@ -46,8 +51,6 @@ export default class RoleController {
|
||||
logger.info("Managing roles", { guildId, requestId })
|
||||
|
||||
const announcementRole = await this.getAnnouncementRoleForGuild(guild, requestId)
|
||||
if (!announcementRole)
|
||||
throw new Error(`No announcementRole found in guild ${guildId}`)
|
||||
|
||||
const usersWhoWantRole: User[] = (await reaction.users.fetch()).filter(user => !user.bot).map(user => user)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user