|
3 | 3 | internal class ServerInfoCommands |
4 | 4 | { |
5 | 5 | [Command("serverinfo")] |
6 | | - [Description("Look up information about a server.")] |
| 6 | + [Description("Look up information about this server.")] |
7 | 7 | [InteractionInstallType(DiscordApplicationIntegrationType.GuildInstall)] |
8 | | - public static async Task ServerInfoCommandAsync(SlashCommandContext ctx, |
9 | | - [Parameter("server"), Description("The ID of the server to look up. Defaults to the current server if you're not using this in DMs.")] |
10 | | - string guildId = default) |
| 8 | + [InteractionAllowedContexts(DiscordInteractionContextType.Guild)] |
| 9 | + public static async Task ServerInfoCommandAsync(SlashCommandContext ctx) |
11 | 10 | { |
12 | 11 | await ctx.DeferResponseAsync(ephemeral: ctx.Interaction.ShouldUseEphemeralResponse(false)); |
13 | 12 |
|
14 | | - DiscordGuild guild; |
15 | | - |
16 | | - if (ctx.Channel.IsPrivate && guildId == default) |
17 | | - { |
18 | | - await ctx.FollowupAsync(new DiscordFollowupMessageBuilder() |
19 | | - .WithContent("You can't use this command in DMs without specifying a server ID! Please try again.") |
20 | | - .AsEphemeral(ephemeral: ctx.Interaction.ShouldUseEphemeralResponse(false))); |
21 | | - return; |
22 | | - } |
23 | | - |
24 | | - if (guildId == default) |
25 | | - { |
26 | | - guild = ctx.Guild; |
27 | | - } |
28 | | - else |
29 | | - { |
30 | | - try |
31 | | - { |
32 | | - guild = await ctx.Client.GetGuildAsync(Convert.ToUInt64(guildId)); |
33 | | - } |
34 | | - catch (Exception ex) when (ex is UnauthorizedException or NotFoundException) |
35 | | - { |
36 | | - await ctx.FollowupAsync(new DiscordFollowupMessageBuilder() |
37 | | - .WithContent("Sorry, I can't read the details for that server because I'm not in it or it doesn't exist!") |
38 | | - .AsEphemeral(ephemeral: ctx.Interaction.ShouldUseEphemeralResponse(false))); |
39 | | - return; |
40 | | - } |
41 | | - catch (FormatException) |
42 | | - { |
43 | | - await ctx.FollowupAsync(new DiscordFollowupMessageBuilder() |
44 | | - .WithContent("That doesn't look like a valid server ID! Please try again.") |
45 | | - .AsEphemeral(ephemeral: ctx.Interaction.ShouldUseEphemeralResponse(false))); |
46 | | - return; |
47 | | - } |
48 | | - } |
49 | | - |
50 | | - var description = "None"; |
51 | | - |
52 | | - if (guild.Description is not null) description = guild.Description; |
53 | | - |
54 | | - var createdAt = $"{guild.Id.ToUnixTimeSeconds()}"; |
55 | | - |
56 | | - var categoryCount = guild.Channels.Count(channel => channel.Value.Type == DiscordChannelType.Category); |
57 | | - |
58 | | - var embed = new DiscordEmbedBuilder() |
59 | | - .WithColor(Setup.Constants.BotColor) |
60 | | - .AddField("Server Owner", $"{(await guild.GetGuildOwnerAsync()).GetFullUsername()}") |
61 | | - .AddField("Description", $"{description}") |
62 | | - .AddField("Created on", $"<t:{createdAt}:F> (<t:{createdAt}:R>)") |
63 | | - .AddField("Channels", $"{guild.Channels.Count - categoryCount}", true) |
64 | | - .AddField("Categories", $"{categoryCount}", true) |
65 | | - .AddField("Roles", $"{guild.Roles.Count}", true) |
66 | | - .AddField("Members", $"{guild.MemberCount}", true) |
67 | | - .WithThumbnail($"{guild.IconUrl}") |
68 | | - .WithFooter($"Server ID: {guild.Id}"); |
69 | | - |
70 | | - await ctx.FollowupAsync(new DiscordFollowupMessageBuilder() |
71 | | - .WithContent($"Server Info for **{guild.Name}**") |
72 | | - .AddEmbed(embed) |
| 13 | + await ctx.FollowupAsync(new DiscordFollowupMessageBuilder(await ctx.Guild.CreateInfoMessageAsync()) |
73 | 14 | .AsEphemeral(ephemeral: ctx.Interaction.ShouldUseEphemeralResponse(false))); |
74 | 15 | } |
75 | 16 | } |
0 commit comments