Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Utility Functions

In this lesson, you’ll clean up your code by using more functions from discord.py, namely the utility functions. The first utility, discord.utils.find(), can improve the simplicity and readability of this code by replacing the for loop with an intuitive, abstracted function. find() takes a function, called a predicate, which identifies some characteristic of the element in the iterable that you’re looking for.

The other utility you’ll practice with is get(), which takes the iterable and some keyword arguments. The keyword arguments represent attributes of the elements in the iterable that must all be satisfied for get() to return the element.

Comments & Discussion

Become a Member to join the conversation.