Skip to content

Commit

Permalink
🐛 コマンドの条件分岐をしっかり動作するように修正 (backend/src/commands/genbutton.ts backend/…
Browse files Browse the repository at this point in the history
…src/commands/genrole.ts backend/src/discord.ts)
  • Loading branch information
HidemaruOwO committed Jan 14, 2023
1 parent 049f0fa commit c23cdcb
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 220 deletions.
85 changes: 43 additions & 42 deletions backend/src/commands/genbutton.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
import {
Client,
BaseCommandInteraction,
MessageButton,
MessageActionRow,
Client,
BaseCommandInteraction,
MessageButton,
MessageActionRow,
} from "discord.js";
import { Command } from "../interface";

const cmd: Command = {
data: {
name: "genbutton",
description: "認証ボタンを作成します",
defaultMemberPermissions: ["ADMINISTRATOR"],
},
async execute(client: Client, interaction: BaseCommandInteraction) {
const guild = interaction.guild;
await interaction.reply({
content: "ボタンを作成します",
ephemeral: true,
});
const role = guild?.roles.cache.find((role) => role.name === "verified");
if (role === undefined) {
await interaction.editReply({
content: "Verifiedロールが存在しません",
data: {
name: "genbutton",
description: "認証ボタンを作成します",
defaultMemberPermissions: ["ADMINISTRATOR"],
},
async execute(client: Client, interaction: BaseCommandInteraction) {
const guild = interaction.guild;
await interaction.reply({
content: "ボタンを作成します",
ephemeral: true,
});
return;
}
const button = new MessageButton()
.setCustomId("verify")
.setStyle("PRIMARY")
.setLabel("認証")
.setEmoji("✅");
await interaction.channel?.send({
embeds: [
{
title: "認証方法",
description: "認証を行うには、以下のボタンを押してください",
color: "RANDOM",
timestamp: new Date(),
footer: {
text: "©️ HidemaruOwO | Discord hCaptcha",
},
},
],
components: [new MessageActionRow().addComponents(button)],
});
await interaction.editReply({ content: "ボタンを作成しました" });
},
const role = guild?.roles.cache.find((role) => role.name === "verified");
if (role === void 0) {
await interaction.editReply({
content:
"Verifiedロールが存在しません\n`/genrole`コマンドを実行して再度お試しください",
});
return;
}
const button = new MessageButton()
.setCustomId("verify")
.setStyle("PRIMARY")
.setLabel("認証")
.setEmoji("✅");
await interaction.channel?.send({
embeds: [
{
title: "認証方法",
description: "認証を行うには、以下のボタンを押してください",
color: "RANDOM",
timestamp: new Date(),
footer: {
text: "©️ HidemaruOwO | Discord hCaptcha",
},
},
],
components: [new MessageActionRow().addComponents(button)],
});
await interaction.editReply({ content: "ボタンを作成しました" });
},
};

export { cmd };
56 changes: 33 additions & 23 deletions backend/src/commands/genrole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,40 @@ import { Client, BaseCommandInteraction } from "discord.js";
import { Command } from "../interface";

const cmd: Command = {
data: {
name: "genrole",
description: "Verifiedロールを作成します",
defaultMemberPermissions: ["ADMINISTRATOR"],
},
async execute(client: Client, interaction: BaseCommandInteraction) {
const guild = interaction.guild;
await interaction.reply({
content: "ロールを作成します",
ephemeral: true,
});
const role = guild?.roles.cache.find((role) => role.name === "verified");
console.log(role);
if (!role === undefined) {
await interaction.editReply({
content: "Verifiedロールが存在します",
data: {
name: "genrole",
description: "Verifiedロールを作成します",
defaultMemberPermissions: ["ADMINISTRATOR"],
},
async execute(client: Client, interaction: BaseCommandInteraction) {
const guild = interaction.guild;
await interaction.reply({
content: "ロールを作成します",
ephemeral: true,
});
return;
}
guild?.roles.create({ name: "verified" });
await interaction.editReply({
content: "ロールを作成しました",
});
},

const role = guild?.roles.cache.find((role) => role.name === "verified");
if (role === void 0) {
try {
guild?.roles.create({ name: "verified" });
} catch (err) {
await interaction.editReply({
content:
"ロールの作成に失敗しました\n権限が不足している可能性があります",
});
return;
}

await interaction.editReply({
content: "ロールを作成しました",
});
} else {
await interaction.editReply({
content: "Verifiedロールが存在します",
});
return;
}
},
};

export { cmd };
Loading

0 comments on commit c23cdcb

Please sign in to comment.