Disabling buttons can be useful in Discord servers to prevent users from clicking on buttons that are no longer relevant. By disabling a button, you can inform users why the button is no longer clickable and avoid confusion or frustration.
By the end of this lesson, you will be able to create a button that will disable itself when a submissions for a book-club have closed.
Instructor: [0:00] Everything is currently running as expected. The last thing is if a user clicks this button again, we get left in this loading state and then we finally get this interaction failed. Let's update this a little bit to show that our user has already been added to our book club.
[0:21] Instead of our filter, let's go ahead and take this ID and set it to a variable. We'll call it hasBookClubRoll. Then if the user has the book club roll, we'll reply with, "You've already been added to the book club." Otherwise, return, the user does not have the BookClubRoll. Now, let's go and save this, and give it a shot.
[1:14] No Discord app, let's run our command again. Testing, two, three, four. Three people in three hours. Hit Enter. Here we go. Give it a Thumbs Up, we were added. Let's hit it again. You've already been added to the book club.
[1:31] Quick side note, people can use this to spam your Discord. We don't want people to be able to do this. Inside here, turn this into an object. Content is equal to that. Then, at the end, we can add Ephemeral is True. Now, we do this one more time, we hit Thumbs Up.
[2:11] Now, if we hit Thumbs Up again, we get a private message, you've already been added to the book club. Now, let's check on our other account. We don't see that extra message. We can click this as many times as we want.
[2:29] The last thing is, we want this button to not be able to be clicked once our submissions have closed. To do that, we can create a new button. Let's do that right underneath our Filter. We'll create a new button called Disabled Button. We'll create this basically the exact same way we did with the previous button.
[2:54] We'll set the CustomId to primary, set the style to be ButtonStyle.Primary. Then here, we're going to set a label saying Submissions Closed. And here, we can set Disabled to True. Now, with this button, we can head down into our collector. We can edit our reply.
[3:51] We want our embedded message to be the exact same as it was. Embed message. Our component is going to be our Disabled Button. Now, let's save this. Head back to our Discord application. Run our command one last time.
[4:18] Let's do "two people ends in two hours". Hit enter. I can hit the Thumbs Up here. Let's head over to our other account, and hit Thumbs Up over here. Now, we get our new button that will not let us click on it, and it lets us know why these submissions are closed.
[4:43] If we check our console.log here, we can see Collected Object Map. If we check our console.log here, we can see Collection Object Map. Let's fix that really fast to be Size. Then, let's go ahead and run it one last time, just to double-check.
[5:10] With that, our bot is finished.
Member comments are a way for members to communicate, interact, and ask questions about a lesson.
The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io
Be on-Topic
Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.
Avoid meta-discussion
Code Problems?
Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context
Details and Context
Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!