API reference
Objects
Every attribute you can read on a user, server, channel, message, role and interaction.
Your code gets ready-made objects, like user, server and channel. This page lists what you can read on each one.
Use these names exactly. A guessed name, like user.name, fails.
Read here, act with helpers
Read attributes from these objects. To do something, like send, add a role or edit, use the helper functions in the API reference. channel.send(...), message.respond(...), member.add_role(...) and member.remove_role(...) are blocked.
Which objects you get depends on where your code runs. See Event variables.
user#
The member who ran the command, or the member an event is about.
| Attribute | What it is |
|---|---|
id | The user ID. |
mention | A ping, like @Alex. |
username | The account name. |
global_name | The display name set on the account. |
display_name | The name shown in this server. Use this for most text. |
nickname | The server nickname, or None. |
avatar_url | The avatar link, or None. |
banner_url | The banner link, or None. |
display_avatar_url | The avatar link, with Discord's default as a fallback. |
roles | The member's roles. |
role_names | Role names, without @everyone. |
role_mentions | Role pings, without @everyone. |
role_ids | Role IDs. |
top_role | The highest role. |
is_bot | True for bots. |
is_boosting | True when they boost the server. |
is_timed_out | True when they are timed out. |
joined_at | When they joined the server. |
created_at | When the account was made. |
unix_joined_at | Join time as a Unix number, for <t:...:R>. |
unix_created_at | Account age as a Unix number. |
premium_since | When they started boosting, or None. |
accent_color | Their profile color. |
status | Their online status. |
Methods: get_roles(), get_top_role(), get_guild(), get_presence(), communication_disabled_until().
set_content(f"{user.display_name} joined <t:{user.unix_joined_at}:R>.")server#
The server the code runs in.
| Attribute | What it is |
|---|---|
id | The server ID. |
name | The server name. |
description | The server description. |
member_count | How many members it has. |
owner_id | The owner's user ID. |
owner | The owner. |
icon_url | The icon link, or None. |
banner_url | The banner link, or None. |
created_at | When the server was made. |
premium_tier | The boost level, 0 to 3. |
premium_subscription_count | How many boosts it has. |
vanity_url_code | The custom invite code, or None. |
verification_level | The verification setting. |
preferred_locale | The server language. |
features | Discord features the server has. |
rules_channel_id | The rules channel ID. |
system_channel_id | The system messages channel ID. |
afk_channel_id | The AFK voice channel ID. |
Methods: get_member(id), get_members(), get_channel(id), get_channels(), get_role(id), get_roles(), get_emoji(id), get_emojis(), get_voice_state(user), get_my_member().
set_content(f"**{server.name}** has {server.member_count} members and {server.premium_subscription_count} boosts.")channel#
A text, voice or thread channel.
| Attribute | What it is |
|---|---|
id | The channel ID. |
name | The channel name. |
mention | A link, like #general. |
type | The kind of channel. |
topic | The channel topic. |
position | Its place in the list. |
parent_id | The category ID. |
is_nsfw | True for age-restricted channels. |
rate_limit_per_user | The slowmode, in seconds. |
last_message_id | The newest message ID. |
created_at | When it was made. |
Methods: get_guild(), fetch_message(id), fetch_history(), fetch_pins().
message#
A Discord message, for example in a message event.
| Attribute | What it is |
|---|---|
id | The message ID. |
content | The text. |
author | Who sent it. |
member | The sender as a member. |
channel_id | Where it was sent. |
created_at | When it was sent. |
edited_timestamp | When it was last edited, or None. |
attachments | Files on the message. |
embeds | Embeds on the message. |
reactions | Reactions on the message. |
stickers | Stickers on the message. |
poll | The poll, if it is one. |
is_pinned | True when pinned. |
mentions_everyone | True when it pings @everyone. |
user_mentions_ids | IDs of users it pings. |
role_mention_ids | IDs of roles it pings. |
channel_mention_ids | IDs of channels it links. |
referenced_message | The message it replies to. |
webhook_id | Set when a webhook sent it. |
Methods: get_member_mentions(), get_role_mentions(), make_link().
To edit or delete, use edit_message and delete_message. See Messages.
Role#
What you get from get_role(...), user.roles or user.top_role.
| Attribute | What it is |
|---|---|
id | The role ID. |
name | The role name. |
mention | A ping, like @VIP. |
color | The role color. |
position | Its height in the role list. |
permissions | What the role allows. |
is_hoisted | True when shown apart in the member list. |
is_mentionable | True when anyone can ping it. |
is_managed | True when a bot or app owns it. |
unicode_emoji | The role icon emoji, if any. |
created_at | When it was made. |
interaction#
The slash command, click or form submit that started the code.
| Attribute | What it is |
|---|---|
id | The interaction ID. |
guild_id | The server ID. |
channel_id | The channel ID. |
member | Who used it. |
user | Who used it, as a user. |
locale | The user's Discord language. |
created_at | When it happened. |
command_name | The command name. Slash commands only. |
options | The options typed in. Slash commands only. |
custom_id | The button, menu or form ID. Clicks and forms only. |
values | What was picked in a menu, as a list. Clicks only. |
message | The message the button is on. Clicks only. |
There is no interaction.get_channel(). Use the channel variable, or get_channel(...).
To reply, use defer_response, respond_interaction and send_modal. See Interactions.
Embed objects#
See Embeds for what you can read and change on an embed.
Constants#
| Name | Use |
|---|---|
Permissions | Permission names, like Permissions.BAN_MEMBERS. |
Color | A color, like Color.from_hex_code("#ff0000"). |
Spacing | Gap sizes for the separator in new-style messages. |