Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit 3a1dc76

Browse files
committed
Defer before responding to slash commands
1 parent 84cbed8 commit 3a1dc76

4 files changed

Lines changed: 17 additions & 16 deletions

File tree

TabletBot.Discord/SlashCommands/ModerationSlashCommands.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private async Task Delete(SocketSlashCommand command)
169169

170170
var messages = await command.Channel.GetMessagesAsync(amount).FlattenAsync();
171171
await (command.Channel as ITextChannel).DeleteMessagesAsync(messages);
172-
await command.RespondAsync($"Deleted {amount} messages.", ephemeral: true);
172+
await command.FollowupAsync($"Deleted {amount} messages.", ephemeral: true);
173173
}
174174

175175
private async Task Kick(SocketSlashCommand command)
@@ -181,13 +181,13 @@ private async Task Kick(SocketSlashCommand command)
181181
{
182182
await user.KickAsync(reason);
183183
if (reason != null)
184-
await command.RespondAsync($"Kicked {user.Mention} for \"{reason}\".", ephemeral: true);
184+
await command.FollowupAsync($"Kicked {user.Mention} for \"{reason}\".", ephemeral: true);
185185
else
186-
await command.RespondAsync($"Kicked {user.Mention}.", ephemeral: true);
186+
await command.FollowupAsync($"Kicked {user.Mention}.", ephemeral: true);
187187
}
188188
else
189189
{
190-
await command.RespondAsync(
190+
await command.FollowupAsync(
191191
$"This user is not a member of this guild.",
192192
ephemeral: true
193193
);
@@ -205,13 +205,13 @@ private async Task Ban(SocketSlashCommand command)
205205
{
206206
await user.BanAsync(reason: reason);
207207
if (reason != null)
208-
await command.RespondAsync($"Banned {user.Mention} for \"{reason}\".", ephemeral: true);
208+
await command.FollowupAsync($"Banned {user.Mention} for \"{reason}\".", ephemeral: true);
209209
else
210-
await command.RespondAsync($"Banned {user.Mention}.", ephemeral: true);
210+
await command.FollowupAsync($"Banned {user.Mention}.", ephemeral: true);
211211
}
212212
else
213213
{
214-
await command.RespondAsync(
214+
await command.FollowupAsync(
215215
$"This user is not a member of this guild.",
216216
ephemeral: true
217217
);
@@ -243,7 +243,7 @@ private async Task CreateEmbed(SocketSlashCommand command)
243243
if (image != null)
244244
embed = embed.WithImageUrl(image);
245245

246-
await command.RespondAsync(embed: embed.Build());
246+
await command.FollowupAsync(embed: embed.Build());
247247
}
248248
}
249249
}

TabletBot.Discord/SlashCommands/SlashCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public async Task Invoke(SocketSlashCommand command)
2222
var user = command.User as IGuildUser;
2323
if (HasCorrectPermissions(user))
2424
{
25+
await command.DeferAsync(true);
2526
await Handler(command);
2627
}
2728
else

TabletBot.Discord/SlashCommands/SnippetSlashCommands.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ private async Task ShowSnippet(SocketSlashCommand command)
144144
var snippet = command.GetValue<string>("snippet");
145145

146146
if (SnippetEmbeds.TryGetSnippetEmbed(_settings, snippet, out var embed))
147-
await command.RespondAsync(embed: embed.Build());
147+
await command.FollowupAsync(embed: embed.Build());
148148
else
149-
await command.RespondAsync("Could not find snippet");
149+
await command.FollowupAsync("Could not find snippet");
150150
}
151151

152152
private async Task SetSnippet(SocketSlashCommand command)
@@ -170,7 +170,7 @@ private async Task SetSnippet(SocketSlashCommand command)
170170

171171
await _settings.Overwrite();
172172
OnUpdate();
173-
await command.RespondAsync(embed: SnippetEmbeds.GetSnippetEmbed(store).Build());
173+
await command.FollowupAsync(embed: SnippetEmbeds.GetSnippetEmbed(store).Build());
174174
}
175175

176176
private async Task RemoveSnippet(SocketSlashCommand command)
@@ -195,11 +195,11 @@ private async Task RemoveSnippet(SocketSlashCommand command)
195195
};
196196
await _settings.Overwrite();
197197
OnUpdate();
198-
await command.RespondAsync(embed: embed.Build());
198+
await command.FollowupAsync(embed: embed.Build());
199199
}
200200
else
201201
{
202-
await command.RespondAsync("Could not find snippet");
202+
await command.FollowupAsync("Could not find snippet");
203203
}
204204
}
205205

@@ -215,7 +215,7 @@ private async Task ExportSnippet(SocketSlashCommand command)
215215
sb.AppendLine(store.Content.Replace(Environment.NewLine, @"\n"));
216216
sb.AppendLine(Formatting.CODE_BLOCK);
217217

218-
await command.RespondAsync(sb.ToString());
218+
await command.FollowupAsync(sb.ToString());
219219
}
220220
}
221221

TabletBot.Discord/SlashCommands/UserSlashCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ private async Task SetTablet(SocketSlashCommand command)
4242
if (tablet != null)
4343
{
4444
await user.ModifyAsync(u => u.Nickname = $"{user.Username} | {tablet}");
45-
await command.RespondAsync($"Your nickname has updated to include your tablet.", ephemeral: true);
45+
await command.FollowupAsync($"Your nickname has updated to include your tablet.", ephemeral: true);
4646
}
4747
else
4848
{
4949
await user.ModifyAsync(u => u.Nickname = null);
50-
await command.RespondAsync($"Your nickname has been reset.", ephemeral: true);
50+
await command.FollowupAsync($"Your nickname has been reset.", ephemeral: true);
5151
}
5252
}
5353
}

0 commit comments

Comments
 (0)