A Feature-rich Discord Bot Framework for Python with comprehensive API coverage and modern interfaces
—
Comprehensive models for all Discord entities like guilds, users, channels, messages, and more.
Represents a Discord server/guild.
class Guild:
id: Snowflake
name: str
owner_id: Snowflake
region: str
afk_channel_id: Optional[Snowflake]
afk_timeout: int
verification_level: VerificationLevel
default_message_notifications: DefaultNotificationLevel
explicit_content_filter: ExplicitContentFilterLevel
roles: List[Role]
emojis: List[CustomEmoji]
features: List[str]
mfa_level: MFALevel
system_channel_id: Optional[Snowflake]
max_presences: Optional[int]
max_members: Optional[int]
description: Optional[str]
banner: Optional[Asset]
premium_tier: PremiumTier
preferred_locale: str
nsfw_level: NSFWLevelKey Methods:
fetch_channels() { .api } - Get all guild channelsfetch_members(limit=1000) { .api } - Get guild memberscreate_text_channel(name, **kwargs) { .api } - Create text channelcreate_voice_channel(name, **kwargs) { .api } - Create voice channelcreate_role(name, **kwargs) { .api } - Create rolefetch_ban(user_id) { .api } - Get ban information for userfetch_bans() { .api } - Get all guild bansRepresents a Discord user.
class User:
id: Snowflake
username: str
discriminator: int
global_name: Optional[str]
avatar: Optional[Asset]
bot: bool
system: bool
mfa_enabled: bool
banner: Optional[Asset]
accent_color: Optional[int]
locale: Optional[str]
verified: bool
email: Optional[str]
flags: UserFlags
premium_type: PremiumType
public_flags: UserFlagsKey Methods:
send(content=None, **kwargs) { .api } - Send DM to userfetch_dm_channel() { .api } - Get DM channel with usermention { .api } - Get user mention stringRepresents a guild member (user in guild context).
class Member(User):
guild: Guild
nick: Optional[str]
avatar: Optional[Asset]
roles: List[Role]
joined_at: datetime
premium_since: Optional[datetime]
deaf: bool
mute: bool
flags: MemberFlags
pending: Optional[bool]
permissions: Optional[Permissions]
communication_disabled_until: Optional[datetime]Key Methods:
add_role(role, reason=None) { .api } - Add role to memberremove_role(role, reason=None) { .api } - Remove role from memberedit(nick=None, roles=None, **kwargs) { .api } - Edit memberkick(reason=None) { .api } - Kick member from guildban(reason=None, delete_message_days=0) { .api } - Ban member from guildtimeout(until, reason=None) { .api } - Timeout memberRepresents the bot's own user account.
class ClientUser(User):
verified: bool
mfa_enabled: boolKey Methods:
edit(username=None, avatar=None) { .api } - Edit bot's profileclass BaseChannel:
id: Snowflake
type: ChannelType
name: Optional[str]
class GuildChannel(BaseChannel):
guild_id: Snowflake
position: int
permission_overwrites: List[PermissionOverwrite]
parent_id: Optional[Snowflake]class GuildText(GuildChannel, MessageableMixin):
topic: Optional[str]
nsfw: bool
last_message_id: Optional[Snowflake]
rate_limit_per_user: int
default_auto_archive_duration: AutoArchiveDuration
permissions: Optional[Permissions]Key Methods:
send(content=None, **kwargs) { .api } - Send message to channelfetch_message(message_id) { .api } - Get specific messagepurge(amount=50, check=None) { .api } - Delete multiple messagescreate_thread(name, **kwargs) { .api } - Create threadset_permissions(target, **permissions) { .api } - Set channel permissionsclass GuildVoice(GuildChannel):
bitrate: int
user_limit: int
rtc_region: Optional[str]
video_quality_mode: VideoQualityModeKey Methods:
connect() { .api } - Connect bot to voice channeledit(name=None, bitrate=None, user_limit=None) { .api } - Edit voice channelclass GuildCategory(GuildChannel):
"""Channel category for organization"""
class GuildNews(GuildText):
"""News/announcement channel"""
class GuildStageVoice(GuildVoice):
"""Stage channel for events"""
class GuildForum(GuildChannel):
"""Forum channel with posts"""
available_tags: List[ThreadTag]
default_reaction_emoji: Optional[PartialEmoji]
class DMChannel(BaseChannel, MessageableMixin):
"""Direct message channel"""
recipient: User
class DMGroup(BaseChannel, MessageableMixin):
"""Group DM channel"""
recipients: List[User]
icon: Optional[Asset]
owner_id: Snowflakeclass Message:
id: Snowflake
channel_id: Snowflake
author: Union[User, Member]
content: str
timestamp: datetime
edited_timestamp: Optional[datetime]
tts: bool
mention_everyone: bool
mentions: List[Union[User, Member]]
mention_roles: List[Role]
mention_channels: List[ChannelMention]
attachments: List[Attachment]
embeds: List[Embed]
reactions: List[Reaction]
nonce: Optional[Union[int, str]]
pinned: bool
webhook_id: Optional[Snowflake]
type: MessageType
activity: Optional[MessageActivity]
application: Optional[Application]
message_reference: Optional[MessageReference]
flags: MessageFlags
referenced_message: Optional[Message]
interaction: Optional[MessageInteraction]
thread: Optional[ThreadChannel]
components: List[ActionRow]
sticker_items: List[StickerItem]Key Methods:
edit(content=None, **kwargs) { .api } - Edit message contentdelete() { .api } - Delete messagereply(content=None, **kwargs) { .api } - Reply to messageadd_reaction(emoji) { .api } - Add emoji reactionremove_reaction(emoji, user=None) { .api } - Remove reactionpin() { .api } - Pin messageunpin() { .api } - Unpin messagecreate_thread(name, **kwargs) { .api } - Create thread from messageclass Embed:
title: Optional[str]
type: str = "rich"
description: Optional[str]
url: Optional[str]
timestamp: Optional[datetime]
color: Optional[int]
footer: Optional[EmbedFooter]
image: Optional[EmbedAttachment]
thumbnail: Optional[EmbedAttachment]
video: Optional[EmbedAttachment]
provider: Optional[EmbedProvider]
author: Optional[EmbedAuthor]
fields: List[EmbedField]Key Methods:
add_field(name, value, inline=False) { .api } - Add embed fieldset_footer(text, icon_url=None) { .api } - Set embed footerset_author(name, url=None, icon_url=None) { .api } - Set embed authorset_thumbnail(url) { .api } - Set embed thumbnailset_image(url) { .api } - Set embed imageclass Attachment:
id: Snowflake
filename: str
description: Optional[str]
content_type: Optional[str]
size: int
url: str
proxy_url: str
height: Optional[int]
width: Optional[int]
ephemeral: boolclass Role:
id: Snowflake
name: str
color: int
hoist: bool
icon: Optional[Asset]
unicode_emoji: Optional[str]
position: int
permissions: Permissions
managed: bool
mentionable: bool
tags: Optional[dict]Key Methods:
edit(name=None, color=None, **kwargs) { .api } - Edit role propertiesdelete(reason=None) { .api } - Delete rolemention { .api } - Get role mention stringclass Permissions:
# Permission flags
ADMINISTRATOR: int = 1 << 3
MANAGE_GUILD: int = 1 << 5
MANAGE_ROLES: int = 1 << 28
MANAGE_CHANNELS: int = 1 << 4
SEND_MESSAGES: int = 1 << 11
READ_MESSAGES: int = 1 << 10
# ... many more permission flagsKey Methods:
has(*permissions) { .api } - Check if has permissionsadd(*permissions) { .api } - Add permissionsremove(*permissions) { .api } - Remove permissionsclass PermissionOverwrite:
id: Snowflake
type: OverwriteType
allow: Permissions
deny: Permissionsclass CustomEmoji:
id: Snowflake
name: str
roles: List[Role]
user: Optional[User]
require_colons: bool
managed: bool
animated: bool
available: boolclass Reaction:
count: int
me: bool
emoji: Union[CustomEmoji, PartialEmoji]Key Methods:
users() { .api } - Get users who reactedremove(user=None) { .api } - Remove reactionclass File:
file: Union[str, bytes, io.IOBase]
filename: Optional[str]
description: Optional[str]
spoiler: bool = FalseUtility Functions:
open_file(path, filename=None, description=None) { .api } - Open file for uploadclass Asset:
url: str
key: str
animated: boolKey Methods:
url { .api } - Get asset URLread() { .api } - Download asset datasave(path) { .api } - Save asset to fileclass Color:
"""Color representation for embeds, roles"""
class BrandColors:
"""Discord brand colors"""
BLURPLE = 0x5865F2
GREEN = 0x57F287
YELLOW = 0xFEE75C
FUCHSIA = 0xEB459E
RED = 0xED4245
class MaterialColors:
"""Material Design colors"""
RED_50 = 0xFFEBEE
# ... many more colors
class FlatUIColors:
"""Flat UI color palette"""
TURQUOISE = 0x1ABC9C
# ... many more colors
class RoleColors:
"""Default Discord role colors"""
DEFAULT = 0x000000
# ... many more colorsSnowflake = int # Discord snowflake ID type
Snowflake_Type = Union[Snowflake, SnowflakeObject, int, str]
# Conversion functions
to_snowflake(data) -> int # Convert to snowflake
to_optional_snowflake(data) -> Optional[int] # Convert to optional snowflake
to_snowflake_list(data) -> List[int] # Convert to snowflake list# Message processing
process_message_payload(content, **kwargs) -> dict
process_allowed_mentions(mentions) -> dict
process_message_reference(reference) -> dict
# Component processing
process_components(components) -> List[dict]
get_components_ids(components) -> List[str]
spread_to_rows(components, max_in_row=5) -> List[ActionRow]
# Embed processing
process_embeds(embeds) -> List[dict]
# Color processing
process_color(color) -> int
process_colour(color) -> int # Alias
# Emoji processing
process_emoji(emoji) -> dict
process_emoji_req_format(emoji) -> str
# Permission processing
process_permission_overwrites(overwrites) -> List[dict]TYPE_ALL_CHANNEL = Union[GuildText, GuildVoice, GuildCategory, ...]
TYPE_GUILD_CHANNEL = Union[GuildText, GuildVoice, GuildCategory, ...]
TYPE_DM_CHANNEL = Union[DMChannel, DMGroup]
TYPE_THREAD_CHANNEL = Union[GuildPublicThread, GuildPrivateThread, ...]
TYPE_VOICE_CHANNEL = Union[GuildVoice, GuildStageVoice]
TYPE_MESSAGEABLE_CHANNEL = Union[GuildText, DMChannel, ...]
TYPE_CHANNEL_MAPPING = {
ChannelType.GUILD_TEXT: GuildText,
ChannelType.DM: DMChannel,
# ... mapping of channel types to classes
}TYPE_COMPONENT_MAPPING = {
ComponentType.ACTION_ROW: ActionRow,
ComponentType.BUTTON: Button,
ComponentType.STRING_SELECT: StringSelectMenu,
# ... mapping of component types to classes
}UPLOADABLE_TYPE = Union[str, bytes, io.IOBase, File]
COLOR_TYPES = Union[int, Color, BrandColors, MaterialColors, ...]class MessageableMixin:
"""Mixin for objects that can receive messages"""
async def send(self, content=None, **kwargs) -> Message:
"""Send message to this channel"""
async def fetch_message(self, message_id: Snowflake) -> Message:
"""Fetch specific message"""
def history(self, limit=100, **kwargs) -> ChannelHistory:
"""Get message history"""class InvitableMixin:
"""Mixin for channels that support invites"""
async def create_invite(self, **kwargs) -> Invite:
"""Create invite for this channel"""
async def fetch_invites(self) -> List[Invite]:
"""Get all invites for this channel"""class ThreadableMixin:
"""Mixin for channels that support threads"""
async def create_thread(self, name: str, **kwargs) -> ThreadChannel:
"""Create thread in this channel"""
async def fetch_active_threads(self) -> ThreadList:
"""Get active threads"""class WebhookMixin:
"""Mixin for webhook functionality"""
async def create_webhook(self, name: str, **kwargs) -> Webhook:
"""Create webhook for this channel"""
async def fetch_webhooks(self) -> List[Webhook]:
"""Get all webhooks for this channel"""Install with Tessl CLI
npx tessl i tessl/pypi-discord-py-interactions