CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-discord-py-interactions

A Feature-rich Discord Bot Framework for Python with comprehensive API coverage and modern interfaces

Pending
Overview
Eval results
Files

discord-models.mddocs/

Discord Objects & Models

Comprehensive models for all Discord entities like guilds, users, channels, messages, and more.

Core Discord Objects

Guild

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: NSFWLevel

Key Methods:

  • fetch_channels() { .api } - Get all guild channels
  • fetch_members(limit=1000) { .api } - Get guild members
  • create_text_channel(name, **kwargs) { .api } - Create text channel
  • create_voice_channel(name, **kwargs) { .api } - Create voice channel
  • create_role(name, **kwargs) { .api } - Create role
  • fetch_ban(user_id) { .api } - Get ban information for user
  • fetch_bans() { .api } - Get all guild bans

User

Represents 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: UserFlags

Key Methods:

  • send(content=None, **kwargs) { .api } - Send DM to user
  • fetch_dm_channel() { .api } - Get DM channel with user
  • mention { .api } - Get user mention string

Member

Represents 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 member
  • remove_role(role, reason=None) { .api } - Remove role from member
  • edit(nick=None, roles=None, **kwargs) { .api } - Edit member
  • kick(reason=None) { .api } - Kick member from guild
  • ban(reason=None, delete_message_days=0) { .api } - Ban member from guild
  • timeout(until, reason=None) { .api } - Timeout member

ClientUser

Represents the bot's own user account.

class ClientUser(User):
    verified: bool
    mfa_enabled: bool

Key Methods:

  • edit(username=None, avatar=None) { .api } - Edit bot's profile

Channels

Base Channel Classes

class BaseChannel:
    id: Snowflake
    type: ChannelType
    name: Optional[str]
    
class GuildChannel(BaseChannel):
    guild_id: Snowflake
    position: int
    permission_overwrites: List[PermissionOverwrite]
    parent_id: Optional[Snowflake]

Text Channels

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 channel
  • fetch_message(message_id) { .api } - Get specific message
  • purge(amount=50, check=None) { .api } - Delete multiple messages
  • create_thread(name, **kwargs) { .api } - Create thread
  • set_permissions(target, **permissions) { .api } - Set channel permissions

Voice Channels

class GuildVoice(GuildChannel):
    bitrate: int
    user_limit: int
    rtc_region: Optional[str]
    video_quality_mode: VideoQualityMode

Key Methods:

  • connect() { .api } - Connect bot to voice channel
  • edit(name=None, bitrate=None, user_limit=None) { .api } - Edit voice channel

Other Channel Types

class 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: Snowflake

Messages & Content

Message

class 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 content
  • delete() { .api } - Delete message
  • reply(content=None, **kwargs) { .api } - Reply to message
  • add_reaction(emoji) { .api } - Add emoji reaction
  • remove_reaction(emoji, user=None) { .api } - Remove reaction
  • pin() { .api } - Pin message
  • unpin() { .api } - Unpin message
  • create_thread(name, **kwargs) { .api } - Create thread from message

Embed

class 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 field
  • set_footer(text, icon_url=None) { .api } - Set embed footer
  • set_author(name, url=None, icon_url=None) { .api } - Set embed author
  • set_thumbnail(url) { .api } - Set embed thumbnail
  • set_image(url) { .api } - Set embed image

Attachment

class 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: bool

Roles & Permissions

Role

class 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 properties
  • delete(reason=None) { .api } - Delete role
  • mention { .api } - Get role mention string

Permissions

class 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 flags

Key Methods:

  • has(*permissions) { .api } - Check if has permissions
  • add(*permissions) { .api } - Add permissions
  • remove(*permissions) { .api } - Remove permissions

Permission Overwrite

class PermissionOverwrite:
    id: Snowflake
    type: OverwriteType
    allow: Permissions
    deny: Permissions

Emojis & Reactions

Custom Emoji

class CustomEmoji:
    id: Snowflake
    name: str
    roles: List[Role]
    user: Optional[User]
    require_colons: bool
    managed: bool
    animated: bool
    available: bool

Reaction

class Reaction:
    count: int
    me: bool
    emoji: Union[CustomEmoji, PartialEmoji]

Key Methods:

  • users() { .api } - Get users who reacted
  • remove(user=None) { .api } - Remove reaction

Files & Assets

File

class File:
    file: Union[str, bytes, io.IOBase]
    filename: Optional[str]
    description: Optional[str]
    spoiler: bool = False

Utility Functions:

  • open_file(path, filename=None, description=None) { .api } - Open file for upload

Asset

class Asset:
    url: str
    key: str
    animated: bool

Key Methods:

  • url { .api } - Get asset URL
  • read() { .api } - Download asset data
  • save(path) { .api } - Save asset to file

Colors

Color Classes

class 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 colors

Utility Types & Functions

Snowflake Handling

Snowflake = 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

Processing Functions

# 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 Mappings & Constants

Channel Type Mappings

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
}

Component Type Mappings

TYPE_COMPONENT_MAPPING = {
    ComponentType.ACTION_ROW: ActionRow,
    ComponentType.BUTTON: Button,
    ComponentType.STRING_SELECT: StringSelectMenu,
    # ... mapping of component types to classes
}

File Type Constants

UPLOADABLE_TYPE = Union[str, bytes, io.IOBase, File]
COLOR_TYPES = Union[int, Color, BrandColors, MaterialColors, ...]

Mixins

MessageableMixin

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"""

InvitableMixin

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"""

ThreadableMixin

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"""

WebhookMixin

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

docs

client.md

commands.md

components.md

discord-models.md

events.md

extensions.md

index.md

tile.json