MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / createReactionRoleMessage

Function createReactionRoleMessage

src/services/reactionRoleService.js:125–187  ·  view source on GitHub ↗
(client, guildId, channelId, messageId, roleIds)

Source from the content-addressed store, hash-verified

123}
124
125export async function createReactionRoleMessage(client, guildId, channelId, messageId, roleIds) {
126 try {
127 validateGuildId(guildId);
128 validateMessageId(messageId);
129
130 if (!channelId || typeof channelId !== 'string' || !/^\d{17,19}$/.test(channelId)) {
131 throw createError(
132 `Invalid channel ID: ${channelId}`,
133 ErrorTypes.VALIDATION,
134 'Invalid channel ID provided.',
135 { channelId }
136 );
137 }
138
139 if (!Array.isArray(roleIds) || roleIds.length === 0) {
140 throw createError(
141 'No roles provided',
142 ErrorTypes.VALIDATION,
143 'You must provide at least one role.',
144 { roleIds }
145 );
146 }
147
148 if (roleIds.length > MAX_ROLES_PER_MESSAGE) {
149 throw createError(
150 `Too many roles: ${roleIds.length}`,
151 ErrorTypes.VALIDATION,
152 `You can only add up to ${MAX_ROLES_PER_MESSAGE} roles per reaction role message.`,
153 { roleIds, limit: MAX_ROLES_PER_MESSAGE }
154 );
155 }
156
157 for (const roleId of roleIds) {
158 validateRoleId(roleId);
159 await validateRoleSafety(client, guildId, roleId);
160 }
161
162 const reactionRoleData = {
163 guildId,
164 channelId,
165 messageId,
166 roles: roleIds,
167 createdAt: new Date().toISOString()
168 };
169
170 const key = `reaction_roles:${guildId}:${messageId}`;
171 await client.db.set(key, reactionRoleData);
172
173 logger.info(`Created reaction role message ${messageId} in guild ${guildId} with ${roleIds.length} roles`);
174 return reactionRoleData;
175 } catch (error) {
176 if (error.name === 'TitanBotError') {
177 throw error;
178 }
179 logger.error(`Error creating reaction role message in guild ${guildId}:`, error);
180 throw createError(
181 `Database error creating reaction role message`,
182 ErrorTypes.DATABASE,

Callers 1

handleSetupFunction · 0.90

Calls 6

createErrorFunction · 0.90
validateGuildIdFunction · 0.85
validateMessageIdFunction · 0.85
validateRoleIdFunction · 0.85
validateRoleSafetyFunction · 0.85
setMethod · 0.45

Tested by

no test coverage detected