generated from lucxjo/template
(#2) Added perk management for members.
Closes #2 Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
e9bc78e9ff
commit
06e42b61e3
70
src/commands/perks.ts
Normal file
70
src/commands/perks.ts
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
import {
|
||||||
|
ApplicationCommandOptionType,
|
||||||
|
Channel,
|
||||||
|
CommandInteraction,
|
||||||
|
} from "discord.js";
|
||||||
|
import { Discord, Slash, SlashGroup, SlashOption } from "discordx";
|
||||||
|
import { prisma } from "../main.js";
|
||||||
|
|
||||||
|
@Discord()
|
||||||
|
@SlashGroup({ description: "Manage your booster perks", name: "perks" })
|
||||||
|
@SlashGroup("perks")
|
||||||
|
export class Perks {
|
||||||
|
@Slash({ description: "Manage your role" })
|
||||||
|
async role(
|
||||||
|
@SlashOption({
|
||||||
|
name: "name",
|
||||||
|
description: "Change the name of your role",
|
||||||
|
type: ApplicationCommandOptionType.String,
|
||||||
|
})
|
||||||
|
name?: string,
|
||||||
|
@SlashOption({
|
||||||
|
name: "colour",
|
||||||
|
description: "Change the colour of your role (in hex)",
|
||||||
|
type: ApplicationCommandOptionType.String,
|
||||||
|
})
|
||||||
|
colour?: string,
|
||||||
|
channel: Channel,
|
||||||
|
interaction: CommandInteraction
|
||||||
|
) {
|
||||||
|
const m = await prisma.member.findUnique({
|
||||||
|
where: {
|
||||||
|
dgid_duid: {
|
||||||
|
dgid: interaction.guildId!,
|
||||||
|
duid: interaction.user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!m || !m.booster_role_id) {
|
||||||
|
interaction.reply({
|
||||||
|
content:
|
||||||
|
"It appears that you may not be a booster of this guild, contact <@207603534789738496> if you think this is a mistake.",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const r = await interaction.guild?.roles.fetch(m.booster_role_id);
|
||||||
|
if (r) {
|
||||||
|
await interaction.guild?.roles.edit(r, {
|
||||||
|
name: name ?? undefined,
|
||||||
|
color:
|
||||||
|
colour != undefined
|
||||||
|
? colour.startsWith("#")
|
||||||
|
? parseInt(colour.replace("#", "0x"), 16)
|
||||||
|
: parseInt(`0x${colour}`)
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
|
interaction.reply({
|
||||||
|
content: "Role updated!",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
interaction.reply({
|
||||||
|
content:
|
||||||
|
"It appears that you may not be a booster of this guild, contact <@207603534789738496> if you think this is a mistake.",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue