137 role command cannot read properties of undefined #141

Merged
Vylpes merged 5 commits from 137-role-command-cannot-read-properties-of-undefined into develop 2022-04-23 18:43:30 +01:00
2 changed files with 16 additions and 4 deletions
Showing only changes of commit 62dc3a8d6e - Show all commits

View file

@ -5,7 +5,7 @@ bot.prefix: The bot prefix for the server (Default: "v!")
commands.disabled: Disabled commands, separated by commas (Default: "")
role.assignable: List of roles assignable to user (Default: [])
role.assignable: List of roles assignable to user, separated by commas (Default: "")
role.moderator: The moderator role name (Default: "Moderator")
role.administrator: The administrator role name (Default: "Administrator")
role.muted: The muted role name (Default: "Muted")

View file

@ -4,6 +4,7 @@ import { Role as DiscordRole } from "discord.js";
import { Command } from "../type/command";
import { ICommandContext } from "../contracts/ICommandContext";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import SettingsHelper from "../helpers/SettingsHelper";
export default class Role extends Command {
constructor() {
@ -13,12 +14,23 @@ export default class Role extends Command {
}
public override async execute(context: ICommandContext) {
const roles = process.env.COMMANDS_ROLE_ROLES!.split(',');
if (!context.message.guild) return;
const roles = await SettingsHelper.GetSetting("role.assignable", context.message.guild.id);
if (!roles) {
const errorEmbed = new ErrorEmbed(context, "Unable to find any assignable roles");
errorEmbed.SendToCurrentChannel();
return;
}
const rolesArray = roles.split(",");
if (context.args.length == 0) {
this.SendRolesList(context, roles);
this.SendRolesList(context, rolesArray);
} else {
await this.ToggleRole(context, roles);
await this.ToggleRole(context, rolesArray);
}
}