This commit is contained in:
Erik 2022-07-17 23:56:05 +03:00
parent 722b514cef
commit 482a38a80b
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
4 changed files with 15 additions and 7 deletions

View File

@ -143,4 +143,8 @@ Successfully removed all your selfroles.
[COMMAND_SELFROLE_INVALID]
{emoji_failure} The following roles are not self-assignable:
**{roles}**
[COMMAND_SELFROLE_TOOHIGH]
{emoji_failure} The following roles are too high for the bot to manage:
**{roles}**

View File

@ -34,12 +34,16 @@ class SelfroleCommand extends SlashCommand {
const { guild, member } = invoker;
const { selfrole } = await guild.settings();
if (!selfrole.roles.length) return { index: 'COMMAND_SELFROLE_NONE', emoji: 'failure' };
const ownHighest = guild.me.roles.highest;
const memberRoles = member.roles.cache.map((r) => r.id);
const tooHigh = roles?.value.filter((r) => r.position > ownHighest.position);
const invalid = roles?.value.filter((r) => !selfrole.roles.includes(r.id)) || [];
const _roles = roles?.value.filter((r) => selfrole.roles.includes(r.id)) || [];
let warning = null;
if (invalid.length) warning = guild.format('COMMAND_SELFROLE_INVALID', { roles: invalid.map((r) => r.name).join('**, **') });
const _roles = roles?.value.filter((r) => selfrole.roles.includes(r.id) && !tooHigh.some((x) => x.id === r.id)) || [];
// console.log(tooHigh, invalid, _roles);
let warning = '';
if (invalid.length) warning += guild.format('COMMAND_SELFROLE_INVALID', { roles: invalid.map((r) => r.name).join('**, **') });
if (tooHigh.length) warning += `\n\n${guild.format('COMMAND_SELFROLE_TOOHIGH', { roles: tooHigh.map((r) => r.name).join('**, **') })}`;
if(!_roles.length && subcommand !== 'clear') return { content: warning };
let index = null,

View File

@ -95,9 +95,9 @@ class SelfroleSetting extends Setting {
components
};
const msg = await oldChannel.messages.fetch(setting.message).catch(() => null);
if (msg && newChannel === oldChannel) {
await msg.edit(payload);
if (newChannel === oldChannel) {
const msg = await oldChannel.messages.fetch(setting.message).catch(() => null);
if(msg) await msg.edit(payload);
} else {
const msg = await newChannel.send(payload);
setting.message = msg.id;

View File

@ -209,7 +209,7 @@ class Setting extends Component {
if (!response) return { error: true, message: invoker.format('ERR_TIMEOUT') };
const content = response.content.toLowerCase();
if(invoker.channel.permissionsFor(invoker.guild.me).has('MANAGE_MESSAGES'))
await response.delete();
await response.delete().catch(() => null);
if (['cancel', 'abort', 'exit'].includes(content)) return {
error: true,
message: invoker.format('ERR_CANCEL')