diff --git a/src/client/components/settings/utility/Selfrole.ts b/src/client/components/settings/utility/Selfrole.ts index e887cb8..29fee2e 100644 --- a/src/client/components/settings/utility/Selfrole.ts +++ b/src/client/components/settings/utility/Selfrole.ts @@ -1,4 +1,4 @@ -import { CommandError, Setting } from '../../../interfaces/index.js'; +import { Setting } from '../../../interfaces/index.js'; import DiscordClient from '../../../DiscordClient.js'; import InvokerWrapper from '../../wrappers/InvokerWrapper.js'; import { CommandOptionType, CommandParams } from '../../../../../@types/Client.js'; @@ -9,7 +9,6 @@ import Emojis from '../../../../constants/Emojis.js'; class SelfroleSetting extends Setting { - constructor (client: DiscordClient) { super(client, { @@ -77,8 +76,9 @@ class SelfroleSetting extends Setting // old channel for deleting old message if one exists const oldChannel = await guild.resolveChannel(setting.channel); const newChannel = channel?.asChannel || oldChannel; - if (!newChannel?.isTextBased()) - throw new CommandError(invoker, { index: 'ERR_INVALID_CHANNEL_TYPE' }); + if (newChannel && !newChannel.isTextBased()) + // throw new CommandError(invoker, { index: 'ERR_INVALID_CHANNEL_TYPE' }); + return { error: true, index: 'ERR_INVALID_CHANNEL_TYPE' }; if (channel) setting.channel = channel.asChannel.id; // Set the new channel if one is given if (text) @@ -95,11 +95,15 @@ class SelfroleSetting extends Setting } } - if (setting.roles.length && setting.channel && setting.roles.length <= 25) + if (newChannel && setting.roles.length && setting.channel && setting.roles.length <= 25) { + const perms = newChannel.permissionsFor(this.client.user!); + const missing = perms?.missing([ 'SendMessages', 'ViewChannel' ]) ?? []; + if (missing.length) + return { error: true, index: 'ERR_CHANNEL_PERMS', params: { perms: missing.join('`, `'), channel: newChannel.name } }; const resolvedRoles = await guild.resolveRoles(setting.roles); const selectMenu: StringSelectMenuComponentData = { - type: ComponentType.SelectMenu, + type: ComponentType.StringSelect, customId: 'selfrole-select', maxValues: resolvedRoles.length, options: resolvedRoles.map((r) => @@ -137,13 +141,10 @@ class SelfroleSetting extends Setting const msg = await newChannel.send(payload); setting.message = msg.id; } - } return { index: 'SETTING_SUCCESS_ALT' }; - } - } export default SelfroleSetting; \ No newline at end of file