Skip to content

Commit 8cd1088

Browse files
RacciRacci
Racci
authored and
Racci
committed
fix: Forgot to make the required role check
1 parent 93143a1 commit 8cd1088

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/main/kotlin/dev/racci/elixir/extensions/RoleSelector.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ class RoleSelector: Extension() {
136136
} else ""
137137
}
138138

139+
private suspend fun requiredRoleCheck(
140+
requiredRole: RoleBehavior?,
141+
member: MemberBehavior,
142+
context: PublicInteractionButtonContext,
143+
): String? {
144+
return if(requiredRole != null && !member.asMember().hasRole(requiredRole)) {
145+
context.interactionResponse.followUpEphemeral {
146+
ephemeral = true
147+
content = "Sorry, You need the ${requiredRole.fetchRole().name} to be able to get this."
148+
}
149+
null
150+
} else ""
151+
}
152+
139153
@OptIn(KordPreview::class)
140154
@Suppress("UNCHECKED_CAST")
141155
private suspend fun addRoleSelector(
@@ -195,6 +209,12 @@ class RoleSelector: Extension() {
195209
this,
196210
) ?: return@action
197211

212+
requiredRoleCheck(
213+
RoleBehavior(GUILD_ID, Snowflake(role["requiredRoleId"] as ULong), kord),
214+
member,
215+
this
216+
) ?: return@action
217+
198218
member.addRole(roleBehavior.id, "Role Selections")
199219
}
200220
}

0 commit comments

Comments
 (0)