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 14 additions and 4 deletions
Showing only changes of commit ae1b5f237c - Show all commits

View file

@ -28,14 +28,15 @@ export default class Role extends Command {
const rolesArray = roles.split(","); const rolesArray = roles.split(",");
if (context.args.length == 0) { if (context.args.length == 0) {
this.SendRolesList(context, rolesArray); await this.SendRolesList(context, rolesArray, context.message.guild.id);
} else { } else {
await this.ToggleRole(context, rolesArray); await this.ToggleRole(context, rolesArray);
} }
} }
public SendRolesList(context: ICommandContext, roles: String[]): ICommandReturnContext { public async SendRolesList(context: ICommandContext, roles: String[], serverId: string): Promise<ICommandReturnContext> {
const description = `Do ${process.env.BOT_PREFIX}role <role> to get the role!\n${roles.join('\n')}`; const botPrefix = await SettingsHelper.GetServerPrefix(serverId);
const description = `Do ${botPrefix}role <role> to get the role!\n${roles.join('\n')}`;
const embed = new PublicEmbed(context, "Roles", description); const embed = new PublicEmbed(context, "Roles", description);
embed.SendToCurrentChannel(); embed.SendToCurrentChannel();

View file

@ -1,4 +1,3 @@
import { getConnection } from "typeorm";
import DefaultValues from "../constants/DefaultValues"; import DefaultValues from "../constants/DefaultValues";
import Server from "../entity/Server"; import Server from "../entity/Server";
import Setting from "../entity/Setting"; import Setting from "../entity/Setting";
@ -47,4 +46,14 @@ export default class SettingsHelper {
await server.Save(Server, server); await server.Save(Server, server);
} }
} }
public static async GetServerPrefix(serverId: string): Promise<string> {
const setting = await this.GetSetting("bot.prefix", serverId);
if (!setting) {
return "v!";
}
VylpesTester commented 2022-04-23 18:31:11 +01:00 (Migrated from github.com)
Review

Not needed

Not needed
return setting;
}
} }