Skip to content

info commands #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as info from "./info";
import * as lockdown from "./lockdown";
import * as moderation from "./moderation";
import * as ping from "./ping";
Expand All @@ -7,6 +8,7 @@ import * as verification from "./verification";
import * as verify from "./verify";

export const commands = {
info,
lockdown,
moderation,
ping,
Expand Down
59 changes: 59 additions & 0 deletions src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Actions } from "@/types";
import {
CommandInteraction,
InteractionType,
SlashCommandBuilder,
} from "discord.js";
import { member, role, server } from "./infos";

export const data = new SlashCommandBuilder()
.setName("info")
.setDescription("Info related commands")
.addSubcommand((subcommand) =>
subcommand
.setName("member")
.setDescription("See info regarding a specific member")
.addMentionableOption((option) =>
option
.setName("member")
.setDescription("Member to look up")
.setRequired(false),
),
)
.addSubcommand((subcommand) =>
subcommand
.setName("role")
.setDescription("See info regarding a specific role")
.addMentionableOption((option) =>
option
.setName("role")
.setDescription("Role to look up")
.setRequired(true),
),
)
.addSubcommand((subcommand) =>
subcommand
.setName("server")
.setDescription("See info regarding the server"),
)
.setDMPermission(false);

export const execute = async (interaction: CommandInteraction) => {
if (
interaction.type !== InteractionType.ApplicationCommand ||
!interaction.isChatInputCommand()
)
return;

const command = interaction.options.getSubcommand();

await interaction.deferReply();

const actions: Actions = {
member: member,
role: role,
server: server,
};

return actions[command](interaction);
};
5 changes: 5 additions & 0 deletions src/commands/infos/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import member from "./member";
import role from "./role";
import server from "./server";

export { member, role, server };
42 changes: 42 additions & 0 deletions src/commands/infos/member.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
CommandInteraction,
EmbedBuilder,
GuildMember,
User,
} from "discord.js";

const member = async (interaction: CommandInteraction) => {
const user = (interaction.options.get("member")?.member ||
interaction.user) as User;

const embed = new EmbedBuilder()
.setColor(0x000000)
.setAuthor({
name: user.displayName,
iconURL: user.avatarURL() as string,
url: user.avatarURL() as string,
})
.setDescription(`Also known as: ${user.username}#${user.discriminator}`)
.addFields(
{
name: "ID",
value: user.id,
},
{
name: "Account Made",
value: user.createdAt.toDateString(),
},
{
name: "Roles",
value: (
interaction.guild?.members.cache.get(user.id) as GuildMember
).roles.cache
.map((role) => role)
.join(", "),
},
);

return interaction.editReply({ embeds: [embed] });
};

export default member;
27 changes: 27 additions & 0 deletions src/commands/infos/role.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
CommandInteraction,
EmbedBuilder,
PermissionsBitField,
} from "discord.js";

const role = async (interaction: CommandInteraction) => {
const role = interaction.options.get("role")?.role;

const embed = new EmbedBuilder()
.setColor(0x000000)
.setTitle(role?.name as string)
.setDescription(`ID: ${role?.id}`)
.addFields(
{
name: "Has Admin?",
value: `${(role?.permissions as Readonly<PermissionsBitField>).has([
PermissionsBitField.Flags.Administrator,
])}`,
},
{ name: "Has Icon?", value: role?.icon ? "true" : "false" },
);

return interaction.editReply({ embeds: [embed] });
};

export default role;
22 changes: 22 additions & 0 deletions src/commands/infos/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CommandInteraction, EmbedBuilder } from "discord.js";

const server = async (interaction: CommandInteraction) => {
const guild = interaction.guild;

const embed = new EmbedBuilder()
.setTitle(guild?.name as string)
.setDescription(guild?.description || "No description")
.addFields(
{ name: "ID", value: guild?.id as string },
{ name: "Owner", value: `<@${guild?.ownerId}>` },
{ name: "Created At", value: guild?.createdAt.toDateString() as string },
{
name: "Roles",
value: guild?.roles.cache.map((role) => role).join(", ") as string,
},
);

return interaction.editReply({ embeds: [embed] });
};

export default server;