Skip to content

Commit 691faf8

Browse files
author
Patrick Sachs
committed
Added: Hints to error messages
1 parent 6dfd25b commit 691faf8

8 files changed

+35
-20
lines changed

SahneeBot/Events/CommandEvent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public override Task Handle(IGuild arg) => HandleAsync(async ctx =>
6161
{
6262
Exception = exception
6363
, GuildId = arg.Id
64+
, Hint = "Your bot is not allowed to create slash commands on your server. Please ensure that you use the official invite link or contact our support."
6465
});
6566
if (error != null)
6667
{

SahneeBot/Events/WelcomeMessageEvent.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ await _welcomeOnNewGuildJoinDiscordFormatter.FormatAndSend(
5151
{
5252
var error = await _discordError.TryGetError<bool>(ctx, new SahneeBotDiscordError.ErrorOptions
5353
{
54-
Exception = exception, GuildId = arg.Id
54+
Exception = exception
55+
, GuildId = arg.Id
56+
, Hint = $"The bot does not have permissions to post its welcome message in the channel {channel.Mention}. If you do not want to grant it permissions to this channel please bind it to one of your other channels using `/config bind <channel>`."
5557
});
5658
if (error != null)
5759
{

SahneeBot/SahneeBotDiscordError.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public struct ErrorOptions
3939
/// The exception.
4040
/// </summary>
4141
public Exception Exception { get; init; }
42+
43+
/// <summary>
44+
/// A hint to what happened.
45+
/// </summary>
46+
public string? Hint { get; init; }
4247
}
4348

4449
/// <summary>
@@ -74,19 +79,19 @@ public struct ErrorOptions
7479
case HttpException {DiscordCode: DiscordErrorCode.InsufficientPermissions}:
7580
{
7681
var prefix = await GetGuildPrefix(ctx, options.GuildId);
77-
return GetMissingRolePermissionsError<T>(prefix);
82+
return GetMissingRolePermissionsError<T>(prefix, options.Hint);
7883
}
7984
// Bot cannot manage roles
8085
case HttpException {HttpCode: HttpStatusCode.Forbidden}:
8186
{
8287
var prefix = await GetGuildPrefix(ctx, options.GuildId);
83-
return GetMissingRolePermissionsError<T>(prefix);
88+
return GetMissingRolePermissionsError<T>(prefix, options.Hint);
8489
}
8590
// Missing intent when invited
8691
case HttpException {DiscordCode: DiscordErrorCode.MissingPermissions}:
8792
{
8893
var prefix = await GetGuildPrefix(ctx, options.GuildId);
89-
return GetMissingRolePermissionsError<T>(prefix);
94+
return GetMissingRolePermissionsError<T>(prefix, options.Hint);
9095
}
9196
default:
9297
{
@@ -103,10 +108,11 @@ private async Task<string> GetGuildPrefix(ITaskContext ctx, ulong? guildId)
103108
return guildState?.WarningRolePrefix.Trim() ?? "n/a";
104109
}
105110

106-
private ISuccess<T> GetMissingRolePermissionsError<T>(string prefix)
111+
private ISuccess<T> GetMissingRolePermissionsError<T>(string prefix, string? hint)
107112
{
108113
var inviteUrl = _cfg["BotSettings:InviteUrl"];
109114
return new Error<T>("The Sahnee-Bot does not have enough permissions on your server.\n" +
115+
(string.IsNullOrEmpty(hint) ? "" : ("**Hint:** " + hint + "\n")) +
110116
"-----------------\n" +
111117
"Please drag the Sahnee-Bot role above all other roles starting with " +
112118
$"\"{prefix.TrimEnd()}\" in your Server Settings and make sure that it has the \"Manage " +

SahneeBot/Tasks/SahneeBotChangeWarningRoleNameTask.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ public override async Task<ISuccess<string>> Execute(ITaskContext ctx, Args args
5656
{
5757
var error = await _discordError.TryGetError<string>(ctx, new SahneeBotDiscordError.ErrorOptions
5858
{
59-
Exception = exception,
60-
GuildId = args.GuildId
59+
Exception = exception
60+
, GuildId = args.GuildId
61+
, Hint = $"The bot could not rename the roles from `{oldPrefix}` to `{args.WarningRolePrefix}`. Please ensure that you use the official invite link and drag the Sahnee-Bot **above** all warning roles in your Server Settings. If that does not help, please contact our support."
6162
});
6263
if (error != null)
6364
{

SahneeBot/Tasks/SahneeBotCleanupWarningRolesTask.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ public async Task<ISuccess<uint>> Execute(ITaskContext ctx, Args arg)
9494
{
9595
error = await _discordError.TryGetError<uint>(ctx, new SahneeBotDiscordError.ErrorOptions
9696
{
97-
Exception = exception,
98-
GuildId = guildId
97+
Exception = exception
98+
, GuildId = guildId
99+
, Hint = $"The bot could not delete the unused warning role {notNeededRole.Mention}. Please ensure that you use the official invite link and drag the Sahnee-Bot **above** all warning roles in your Server Settings. If that does not help, please contact our support."
99100
});
100101
if (error == null)
101102
{

SahneeBot/Tasks/SahneeBotGuildChangeRoleColorTask.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public override async Task<ISuccess<string>> Execute(ITaskContext ctx, Args arg)
6666
{
6767
var error = await _discordError.TryGetError<string>(ctx, new SahneeBotDiscordError.ErrorOptions
6868
{
69-
Exception = exception,
70-
GuildId = arg.GuildId
69+
Exception = exception
70+
, GuildId = arg.GuildId
71+
, Hint = $"The bot could not change the color of your warning roles to `{customColor}`. Please ensure that you use the official invite link and drag the Sahnee-Bot **above** all warning roles in your Server Settings. If that does not help, please contact our support."
7172
});
7273
if (error != null)
7374
{

SahneeBot/Tasks/SahneeBotModifyUserWarningRoleTask.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ public override async Task<ISuccess<ulong>> Execute(ITaskContext ctx, Args args)
9292
}
9393
var error = await _discordError.TryGetError<ulong>(ctx, new SahneeBotDiscordError.ErrorOptions
9494
{
95-
Exception = exception,
96-
GuildId = args.GuildId
95+
Exception = exception
96+
, GuildId = args.GuildId
97+
, Hint = $"Could not remove the old warning role of {currentGuildUser.Mention}. Please ensure that you use the official invite link and drag the Sahnee-Bot **above** all warning roles in your Server Settings. If that does not help, please contact our support."
9798
});
9899
if (error != null)
99100
{
@@ -122,9 +123,8 @@ public override async Task<ISuccess<ulong>> Execute(ITaskContext ctx, Args args)
122123
roleColor = new Color(rgb.R, rgb.G, rgb.B);
123124
}
124125
// Create the new role
125-
newRole = await currentGuild
126-
.CreateRoleAsync(newRoleName, default,
127-
roleColor, false, null);
126+
newRole = await currentGuild.CreateRoleAsync(newRoleName, default
127+
, roleColor, false, null);
128128
// Add the new role to the guild
129129
await currentGuildUser.AddRoleAsync(newRole);
130130
await _checkRoleLimitTask.Execute(ctx, new CheckRoleLimitTask.Args(currentGuild.Id));
@@ -138,8 +138,9 @@ public override async Task<ISuccess<ulong>> Execute(ITaskContext ctx, Args args)
138138
await removeRolesCommand.Undo();
139139
var error = await _discordError.TryGetError<ulong>(ctx, new SahneeBotDiscordError.ErrorOptions
140140
{
141-
Exception = exception,
142-
GuildId = args.GuildId
141+
Exception = exception
142+
, GuildId = args.GuildId
143+
, Hint = $"Could not create the new warning role for {currentGuildUser.Mention}. Please ensure that you use the official invite link and drag the Sahnee-Bot **above** all warning roles in your Server Settings. If that does not help, please contact our support."
143144
});
144145
if (error != null)
145146
{
@@ -164,8 +165,9 @@ public override async Task<ISuccess<ulong>> Execute(ITaskContext ctx, Args args)
164165
await removeRolesCommand.Undo();
165166
var error = await _discordError.TryGetError<ulong>(ctx, new SahneeBotDiscordError.ErrorOptions
166167
{
167-
Exception = exception,
168-
GuildId = args.GuildId
168+
Exception = exception
169+
, GuildId = args.GuildId
170+
, Hint = $"Could not assign the the warning role to {currentGuildUser.Mention}. Please ensure that you use the official invite link and drag the Sahnee-Bot **above** all warning roles in your Server Settings. If that does not help, please contact our support."
169171
});
170172
if (error != null)
171173
{

SahneeBot/Tasks/SahneeBotPostChangelogsToGuildTask.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public override async Task<ISuccess<uint>> Execute(ITaskContext ctx, Args arg)
6969
, new SahneeBotDiscordError.ErrorOptions {
7070
Exception = exception
7171
, GuildId = guildId
72+
, Hint = $"Could not post a message in the channel {channel.Mention}."
7273
});
7374
if (error != null)
7475
{

0 commit comments

Comments
 (0)