Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added difference between get_ commands and fetch_ commands in FAQ #2123

Closed
wants to merge 19 commits into from
Closed
Changes from 2 commits
Commits
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: 12 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ Putting both of these pieces of info together, you get the following: ::
activity = discord.Activity(name='my activity', type=discord.ActivityType.watching)
client = discord.Client(activity=activity)

What is the difference between get_ commands and fetch_ commands?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
get_ commands retrieve from the cache and won't always raise if not found. fetch_ commands always make an API request and if not found, raise. Example: ::
Blue-Robin-Taken marked this conversation as resolved.
Show resolved Hide resolved

role = member.guild.get_role(id) # try to get role without an API request through the cache
if role is not None:
await member.add_roles(role) # if the role is found and returned, then it adds the role and returns
return

# if it's not found in cache, make an API request
role = discord.utils.get(await member.guild.fetch_roles(), id=id)

Copy link
Member

Choose a reason for hiding this comment

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

I think using a simpler example like bot.fetch_user vs bot.get_user would be easier to understand.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, exactly that these function types are the ones to be explained.

How do I send a message to a specific channel?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down