Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4a1abbf
refactor: create services folder and move reactionRole
sora81dev Jun 12, 2026
1f767bc
refactor: create handlerEvents and move onMessageReactionRemove
sora81dev Jun 12, 2026
c59b0e5
chore: update package-lock.json
sora81dev Jun 12, 2026
a13a42f
refactor: move messageReactionAdd events to handlers/events
sora81dev Jun 12, 2026
6bb0ffc
chore: remove unused imports in index.ts
sora81dev Jun 12, 2026
9b3403d
refactor: add env file and apply to index.ts
sora81dev Jun 12, 2026
8c2e4ab
refactor: move env.ts to configs/env.ts
sora81dev Jun 12, 2026
a04631c
fix: logTitle in onMessageReactionRemove event handler
sora81dev Jun 12, 2026
d732ca2
fix: log message in event handler
sora81dev Jun 17, 2026
5904f22
refactor: add runtimeConfig for reactionRoleMessageId
sora81dev Jun 17, 2026
9303e4e
refactor: apply runtimeConfig for index.ts
sora81dev Jun 17, 2026
eee0d04
refactor: add cemicolon to env.ts
sora81dev Jun 17, 2026
4683c14
refactor: migrate VC_ROLE_ID and NOTIFIER_ROLE_ID to configFile
sora81dev Jul 5, 2026
af5e7bd
Merge branch 'sf-kosen:main' into refactor/conciseindexFile
sora81dev Jul 15, 2026
9873435
refactor: migrate BOT_ID and REACTIONROLE_CHANNEL_ID to env.ts
sora81dev Jul 15, 2026
f5a897f
refactor: move runSafely and addRoleSafely to utils/safe.ts
sora81dev Jul 24, 2026
1862bd3
refactor: remove unused import
sora81dev Jul 24, 2026
8376d55
chore: remove reactionRoleMessage in index.ts
sora81dev Jul 24, 2026
1a8cb58
refactor: separate guildMemberAdd event
sora81dev Jul 24, 2026
965c1a9
refactor: export client for future refactor
sora81dev Jul 24, 2026
f555f67
refactor: separate updateMemberCount from index.ts
sora81dev Jul 24, 2026
f3895f7
refactor: auto loading events
sora81dev Jul 24, 2026
30e7015
fix: reactionRole channelid in checkReactionRoleMessage jobs
sora81dev Jul 24, 2026
6b416a2
refactor: separate threadCrate from index.ts
sora81dev Jul 24, 2026
451bae5
refactor: separate guildMemberUpdate from index.ts
sora81dev Jul 24, 2026
98a5d73
refactor: separate logAndSendError from index.ts
sora81dev Jul 24, 2026
0bb1166
refactor: separete interactionCreate from index.ts
sora81dev Jul 24, 2026
c7c47eb
refactor: separate commandRegister from index.ts
sora81dev Jul 24, 2026
8e9e446
refactor: more simple checkReactionRoleMessage
sora81dev Jul 24, 2026
49ba0de
chore: remove client args
sora81dev Jul 24, 2026
4a02dcf
chore: move register to jobs from utils folder
sora81dev Jul 24, 2026
6fddf90
chore: remove package-lock for conflicts
sora81dev Jul 24, 2026
a31abb9
fix: repl role_id to roleID in addReactionRole
sora81dev Jul 24, 2026
7822495
fix: remove client args
sora81dev Jul 24, 2026
19b88a5
refactor: remove unused var
sora81dev Jul 24, 2026
2bfc777
refactor: remove magic number
sora81dev Jul 24, 2026
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
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dotenv from "dotenv"

dotenv.config()

export const env = {
tokens: {
discordToken: process.env.DISCORD_TOKEN
}
}
25 changes: 25 additions & 0 deletions src/handlers/events/onMessageReactionAdd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { MessageReaction, PartialMessageReaction, User, PartialUser } from "discord.js";

import addReactionRole from "../../services/reactionRole/addReactionRole";

export default async function onMessageReactionAdd(reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser) {
const message = reaction.message;
const member = message?.guild?.members.resolve(user.id);

console.log("[INFO] messageReactionAdded");
console.log(` -> message: ${message.content?.toString()}`);
console.log(` -> member : ${member?.displayName}`);

if (!member || !reaction.emoji.name) return;
Comment thread
sora81dev marked this conversation as resolved.

console.log(` -> react : ${reaction.emoji.name}`);

// ReactionRole: ロール付与
if (message.id === reactionRoleMessage) {
try {
await addReactionRole(member, reaction.emoji.name);
} catch (e) {
console.error(e);
}
}
});
25 changes: 25 additions & 0 deletions src/handlers/events/onMessageReactionRemove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { MessageReaction, PartialMessageReaction, PartialUser, User } from "discord.js";
import removeReactionRole from "../../services/reactionRole/removeReactionRole";

export default async function onMessageReactionRemove(reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser) {
const message = reaction.message;
const member = message?.guild?.members.resolve(user.id);

console.log("[INFO] messageReactionAdded");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Incorrect log message — copy-paste from the "add" handler.

The log says "messageReactionAdded" but this handler processes reaction removals.

✏️ Proposed fix
-  console.log("[INFO]  messageReactionAdded");
+  console.log("[INFO]  messageReactionRemoved");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log("[INFO] messageReactionAdded");
console.log("[INFO] messageReactionRemoved");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/handlers/events/onMessageReactionRemove.ts` at line 8, The log in the
onMessageReactionRemove handler is incorrect: update the console.log call inside
onMessageReactionRemove (currently logging "messageReactionAdded") to a correct,
descriptive message such as "messageReactionRemoved" or "messageReactionRemove"
so logs reflect reaction removals; locate the console.log in
onMessageReactionRemove and change only the message string.

console.log(` -> message: ${message.content?.toString()}`);
console.log(` -> member : ${member?.displayName}`);

if (!member || !reaction.emoji.name) return;
Comment thread
tanahiro2010 marked this conversation as resolved.

console.log(` -> react : ${reaction.emoji.name}`);

// ReactionRole: ロール剥奪
if (message.id === reactionRoleMessage) {
try {
await removeReactionRole(member, reaction.emoji.name);
} catch (e) {
console.error(e);
// この先通知処理も追加
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Shared root cause: reactionRoleMessage is inaccessible after extraction.

The handler in src/handlers/events/onMessageReactionRemove.ts references reactionRoleMessage (line 17), but this variable is defined in src/index.ts (line 51) and not passed to the handler when wired at line 301. Both files need coordinated changes: the handler signature must accept reactionRoleMessage as a parameter, and the event registration must pass it via a closure.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/handlers/events/onMessageReactionRemove.ts` around lines 17 - 24, The
handler references reactionRoleMessage from index but that variable is no longer
in scope; update the onMessageReactionRemove handler (in
onMessageReactionRemove.ts) to accept an extra parameter (e.g.,
reactionRoleMessage) alongside the existing parameters used by
removeReactionRole, update its exported function signature and types, and then
modify the event registration where you wire the handler (the
client.on("messageReactionRemove", ...) registration in index.ts) to pass
reactionRoleMessage into the handler via a closure (e.g., client.on(...,
(reaction, user) => onMessageReactionRemove(reaction, user,
reactionRoleMessage))). Ensure imports/exports for onMessageReactionRemove are
adjusted and any TypeScript types for member/reaction parameters remain correct.

}
56 changes: 6 additions & 50 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import { handleVcLeave } from "./handlers/events/vc/leave";
import { handleVcLogger } from "./handlers/events/vc/logger";
import { updateMemberCount, firstJob } from "./jobs/updateMemberCount";
import { loadCommands, loadActions } from "./utils/loader";
import dotenv from "dotenv";
import noticeNewRecruit from "./jobs/noticeNewRecruit";
import addReactionRole from "./handlers/events/reactionRole/addReactionRole";
import removeReactionRole from "./handlers/events/reactionRole/removeReactionRole";
import checkReactionRoleMessage from "./jobs/checkReactionRoleMessage";

dotenv.config({ path: ".env" });
import onMessageReactionRemove from "./handlers/events/onMessageReactionRemove";
import onMessageReactionAdd from "./handlers/events/onMessageReactionAdd";
import { env } from "./env";

// 実行環境に応じてファイルタイプとディレクトリを決定
const FILE_TYPE: string = process.argv[2] === "js" ? ".js" : ".ts";
Expand Down Expand Up @@ -275,52 +273,10 @@ client.on("guildMemberUpdate", async (oldMember, newMember) => {
}
});

client.on("messageReactionAdd", async (reaction, user) => {
const message = reaction.message;
const member = message?.guild?.members.resolve(user.id);

console.log("[INFO] messageReactionAdded");
console.log(` -> message: ${message.content?.toString()}`);
console.log(` -> member : ${member?.displayName}`);

if (!member || !reaction.emoji.name) return;

console.log(` -> react : ${reaction.emoji.name}`);

// ReactionRole: ロール付与
if (message.id === reactionRoleMessage) {
try {
await addReactionRole(member, reaction.emoji.name);
} catch (e) {
console.error(e);
}
}
});

client.on("messageReactionRemove", async (reaction, user) => {
const message = reaction.message;
const member = message?.guild?.members.resolve(user.id);

console.log("[INFO] messageReactionAdded");
console.log(` -> message: ${message.content?.toString()}`);
console.log(` -> member : ${member?.displayName}`);

if (!member || !reaction.emoji.name) return;

console.log(` -> react : ${reaction.emoji.name}`);

// ReactionRole: ロール剥奪
if (message.id === reactionRoleMessage) {
try {
await removeReactionRole(member, reaction.emoji.name);
} catch (e) {
console.error(e);
// この先通知処理も追加
}
}
});
client.on("messageReactionAdd", onMessageReactionAdd);
client.on("messageReactionRemove", onMessageReactionRemove);

export { FILE_TYPE, client, commands, actions };
client.login(process.env.DISCORD_TOKEN).catch((error) => {
client.login(env.tokens.discordToken).catch((error) => {
console.error("[ERROR] Failed to login Discord client:", error);
});
Loading