Skip to content

Commit

Permalink
/role でボタンの文字数制限に引っかかる問題を解消
Browse files Browse the repository at this point in the history
  • Loading branch information
minarin0179 committed Oct 23, 2023
1 parent 654932c commit c0e2e24
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/commands/slashcommands/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,32 @@ export default new SlashCommand({
const roleAdd = args.getRole("付与するロール");
const roleRemove = args.getRole("解除するロール");
const ephemeral = args.getString("ボタンを他の人からも見えるようにする") === "true" ? false : true;
const allowedMentions = { parse: [] };

switch (subCommand) {
case "add":
await reply(interaction, {
content: `${target}${roleAdd}を付与します`,
components: buttonToRow(roleAddButton.build({ target: target, role: roleAdd })),
ephemeral,
allowedMentions,
});
break;
case "remove":
await reply(interaction, {
content: `${roleRemove}をすべてのメンバーから解除します`,
components: buttonToRow(roleRemoveButton.build({ role: roleRemove })),
ephemeral,
allowedMentions,
});
break;
case "change":
if (roleAdd == roleRemove) return reply(interaction, "変更前と変更後のロールが同じです");
await reply(interaction, {
content: `${roleRemove}${roleAdd}に付け替えます`,
components: buttonToRow(roleChangeButton.build({ before: roleRemove, after: roleAdd })),
ephemeral,
allowedMentions,
});
break;
case "self":
Expand All @@ -127,7 +134,7 @@ export default new SlashCommand({
components: roleList.build(rolesSplited, index * 5 + 1),
});
}
return;
break;
}
await interaction.channel?.send(buildRoleRow(roleAdd));
await reply(interaction, "ボタンを作成しました");
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/roleAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default new Button({
build: ({ target, role }: { target: Role; role: Role }) => [
new ButtonBuilder()
.setCustomId(`roleAdd:${target.id},${role.id}`)
.setLabel(`「@${target.name}」に「@${role.name}」を付与`)
.setLabel("付与")
.setStyle(ButtonStyle.Success),
],
execute: async ({ interaction, args }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/buttons/roleChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default new Button({
build: ({ before, after }: { before: Role; after: Role }) => [
new ButtonBuilder()
.setCustomId(`roleChange:${before.id},${after.id}`)
.setLabel(`「@${before.name}」を「@${after.name}」に付け替え`)
.setLabel("付け替え")
.setStyle(ButtonStyle.Primary),
],
execute: async ({ interaction, args }) => {
Expand Down
5 changes: 1 addition & 4 deletions src/components/buttons/roleRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { reply } from "../../utils/Reply";
export default new Button({
customId: "roleRemove",
build: ({ role }: { role: Role }) => [
new ButtonBuilder()
.setCustomId(`roleRemove:${role.id}`)
.setLabel(`「@${role.name}」を解除`)
.setStyle(ButtonStyle.Danger),
new ButtonBuilder().setCustomId(`roleRemove:${role.id}`).setLabel("解除").setStyle(ButtonStyle.Danger),
],
execute: async ({ interaction, args }) => {
const [roleId] = args;
Expand Down

0 comments on commit c0e2e24

Please sign in to comment.