or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

client.mdcommands.mdcomponents.mddiscord-models.mdevents.mdextensions.mdindex.md

index.mddocs/

0

# Discord.py-Interactions

1

2

A modern Python library for building Discord bots with slash commands and interactions.

3

4

## Package Information

5

6

**Name**: `discord-py-interactions`

7

**Language**: Python 3.10+

8

**Installation**: `pip install discord-py-interactions`

9

**Repository**: https://github.com/interactions-py/interactions.py

10

11

## Core Imports

12

13

```python

14

import interactions

15

from interactions import Client, AutoShardedClient, Intents

16

from interactions import slash_command, listen, Extension

17

```

18

19

## Basic Usage

20

21

### Simple Bot Setup

22

23

```python

24

import interactions

25

from interactions import slash_command

26

27

bot = interactions.Client(token="YOUR_BOT_TOKEN", intents=interactions.Intents.DEFAULT)

28

29

@slash_command(name="hello", description="Say hello!")

30

async def hello(ctx):

31

await ctx.send("Hello World!")

32

33

bot.start()

34

```

35

36

### Bot with Events

37

38

```python

39

import interactions

40

from interactions import listen, slash_command, events

41

42

bot = interactions.Client(token="YOUR_BOT_TOKEN")

43

44

@listen()

45

async def on_ready(event: events.Ready):

46

print(f"Logged in as {event.user}")

47

48

@listen()

49

async def on_message_create(event: events.MessageCreate):

50

print(f"Message: {event.message.content}")

51

52

@slash_command(name="ping")

53

async def ping(ctx):

54

await ctx.send("Pong!")

55

56

bot.start()

57

```

58

59

## Architecture

60

61

The library follows a modern, interaction-based architecture:

62

63

1. **Client-Centric Design**: All functionality revolves around the `Client` class

64

2. **Decorator-Based Commands**: Use decorators like `@slash_command` to define commands

65

3. **Event-Driven Architecture**: Listen to Discord and internal events with `@listen()`

66

4. **Type-Safe**: Extensive use of type hints and enums for better development experience

67

5. **Modular Extensions**: Organize code using the `Extension` system

68

69

## Capabilities

70

71

### Client & Bot Management

72

Manage bot lifecycle, configuration, and connection handling.

73

74

```python

75

from interactions import Client, AutoShardedClient, Intents, Status, Activity

76

```

77

78

**Key APIs**:

79

- `Client(token, intents)` { .api }

80

- `AutoShardedClient(token)` { .api }

81

- `client.start()` { .api }

82

- `client.change_presence(status, activity)` { .api }

83

84

[Full Client Documentation](client.md)

85

86

### Discord Objects & Models

87

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

88

89

```python

90

from interactions import Guild, User, Member, Channel, Message, Role, Permissions

91

```

92

93

**Key APIs**:

94

- `Guild.fetch_channels()` { .api }

95

- `User.send(content)` { .api }

96

- `Message.reply(content)` { .api }

97

- `Member.add_role(role)` { .api }

98

99

[Full Discord Models Documentation](discord-models.md)

100

101

### Commands & Interactions

102

Create slash commands, context menus, and handle all interaction types.

103

104

```python

105

from interactions import slash_command, context_menu, SlashContext, ModalContext

106

```

107

108

**Key APIs**:

109

- `@slash_command(name, description)` { .api }

110

- `@context_menu(name, context_type=CommandType.USER)` { .api }

111

- `ctx.send(content, ephemeral=True)` { .api }

112

- `ctx.defer()` { .api }

113

114

[Full Commands Documentation](commands.md)

115

116

### Events & Listeners

117

Comprehensive event system covering Discord gateway events and internal bot events.

118

119

```python

120

from interactions import listen, events

121

```

122

123

**Key APIs**:

124

- `@listen()` { .api }

125

- `events.MessageCreate` { .api }

126

- `events.Ready` { .api }

127

- `events.GuildJoin` { .api }

128

129

[Full Events Documentation](events.md)

130

131

### User Interface Components

132

Interactive components like buttons, select menus, and modals.

133

134

```python

135

from interactions import Button, Modal, ActionRow, StringSelectMenu

136

```

137

138

**Key APIs**:

139

- `Button(style=ButtonStyle.PRIMARY, label="Click Me")` { .api }

140

- `Modal(title="Form", components=[...])` { .api }

141

- `@component_callback("button_id")` { .api }

142

- `@modal_callback("modal_id")` { .api }

143

144

[Full Components Documentation](components.md)

145

146

### Extensions & Utilities

147

Extension system, converters, tasks, and utility functions.

148

149

```python

150

from interactions import Extension, Task, Cooldown, check

151

```

152

153

**Key APIs**:

154

- `class MyExtension(Extension): ...` { .api }

155

- `@Task.create(IntervalTrigger(seconds=60))` { .api }

156

- `@cooldown(Buckets.USER, 1, 30)` { .api }

157

- `@check(lambda ctx: ctx.author.id == OWNER_ID)` { .api }

158

159

[Full Extensions Documentation](extensions.md)