59
discord-interactions Release 4.0.0 goverfl0w Dec 01, 2021

PAGES - Read the Docs

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PAGES - Read the Docs

discord-interactionsRelease 4.0.0

goverfl0w

Dec 01, 2021

Page 2: PAGES - Read the Docs
Page 3: PAGES - Read the Docs

PAGES:

1 What are we good for? 31.1 What does that mean? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Where do I start? 52.1 Quickstart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 API Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.3 Frequently Asked Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

3 Advanced Search 55

i

Page 4: PAGES - Read the Docs

ii

Page 5: PAGES - Read the Docs

discord-interactions, Release 4.0.0

No more hassle with trying to get interactions to work with your Python Discord bot – discord-interactions is nowhere.

discord-interactions is a simple API wrapper for Discord interactions. We’re not here to replace discord.py or anyother fork, but we are here to be the very best Python Discord library there is that implements interactions very well.This is what our library is all about.

PAGES: 1

Page 6: PAGES - Read the Docs

discord-interactions, Release 4.0.0

2 PAGES:

Page 7: PAGES - Read the Docs

CHAPTER

ONE

WHAT ARE WE GOOD FOR?

These are the biggest advantages that you will receive out of using our library:

• Modern library architecture design for easy modularity and scalability.

• Sane HTTP 429 ratelimiting.

• Dynamic object data generation via. dispatch.

• On-demand caching.

• await/async coroutine functionality.

1.1 What does that mean?

We’re basically the library you’ll want to use for these specific things:

• XXX Working with application commands and components. (Interactions)

• XXX Handling data from any text channel, cached and dispatched.

• XXX General permissions handling on guild members.

• XXX Responsive callbacks for components.

We won’t be doing these things as a core aspect of our library, however:

• Voice client capabilities.

• Cooldowns/bucket types.

3

Page 8: PAGES - Read the Docs

discord-interactions, Release 4.0.0

4 Chapter 1. What are we good for?

Page 9: PAGES - Read the Docs

CHAPTER

TWO

WHERE DO I START?

Please look at our pages below to find out where to go further.

2.1 Quickstart

Looking into trying to get started with our library? Well, you’ve come to the right page then!

Note: This quickstart guide is extremely rough and contains experimental code. Do not follow us strictly until v4.0is released! Everything is subject to change in here due to the development of the API wrapper continuously beingreflected.

2.1.1 Installing

discord-interactions is a Python library for the Discord Artificial Programming Interface. (API) A library in Pythonhas to be installed through the pip file. Run this in your terminal/command line in order to install our library:

pip install -U discord-interactions

If you’re unable to run it through your terminal/command line, you need to make sure that it’s accessible as an Envi-ronment Path. Search more on Google for how to do this.

2.1.2 Minimal Bot

Bots can be a little confusing to create. That’s why we’ve decided to try and make the process as streamlined ashumanly possible, in order for it to be friendlier to understand for our fellow bot developers. Please note that a Discordbot should not be your first project if you’re learning how to code. There are plenty of other projects to considerfirst before this, as a Discord bot is not exactly beginner-friendly.

This code block below shows a simple bot being created:

import interactions

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

@bot.command(name="test",description="this is just a test command.",scope=1234567890

(continues on next page)

5

Page 10: PAGES - Read the Docs

discord-interactions, Release 4.0.0

(continued from previous page)

)async def test(ctx):

print("we're here so far.")# await ctx.send("Hello world!")

bot.start()

There’s quite a lot of things that are going on here, so let’s break it down step-by-step:

• import interactions – This is the import line. If this returns a ModuleNotFoundError, please look at ourInstalling section here.

• bot = interactions.Client(token="...") – This is the bot variable that defines our bot. This basicallyinstantiates the Client class, which requires a token keyword-argument to be passed. In order to get a token,please look at the image given below.

• @bot.command() – This is something known as a decorator in Python. This decorator is in charge and re-sponsible of making sure that the Discord API is told about the slash/sub command that you wish to create,and sends an HTTP request correspondingly. Any changes to the information contained in this decorator willbe synchronously updated with the API automatically for you. The scope field shown here is optional, whichrepresents a guild command if you wish to have a command appear in only specific servers that bot is in. Thiscan be a guild object or the ID.

• bot.start() – Finally, this is what tells our library to turn your bot from offline to online.

And it’s really as simple as that! If you would like to learn more about what our library offers, or see more examplesof our code, please be sure to check out our coding examples page on our docs!

2.1.3 Context menus

Documentation for this will be coming soon.

2.1.4 Components

Being able to run your own commands is very useful for a lot of automation-related purposes as a bot developer,however, we also have something that we’re able to introduce for both the developer and a user to use that will be the“sprinkles” on top of a cupcake, so-to-speak: components.

Components are ways of being able to select pre-defined data, or define your own. They’re very simple but quitepowerful when put into practice This code block below shows a simplified implementation of a component:

import interactions

(continues on next page)

6 Chapter 2. Where do I start?

Page 11: PAGES - Read the Docs

discord-interactions, Release 4.0.0

(continued from previous page)

bot = interactions.Client(token="...")button = interactions.Button(

style=interactions.ButtonStyle.PRIMARY,label="hello world!",custom_id="hello"

)

@bot.command(name="test",description="this is just a test command.",scope=1234567890

)async def test(ctx):

await ctx.send("testing", components=button)

@bot.component(button)async def button_response(ctx):

print("someone clicked the button! :O")

This is a design that we ended up choosing to simplify responding to buttons when someone presses on one, and to allowbot developers to plug in which button they want a response to. No more wait_for_component and wait_for func-tions with huge if-else chains; this removes redundancy in your code and overall eases into the practice of modularity.This code block shown above will give a response that will apear something like this:

What kinds of components are there?

As a bot developer, this may be fairly important for you to want to know. Different components provide differenceuser experiences, interactions and results. Currently you can choose between two components that Discord provides:a Button and SelectMenu. You’re able to find these component types here.

How do I send components in a row?

You are also able to organize these components into rows, which are defined as ActionRow’s. It is worth noting thatyou can have only a maximum of 5 per message that you send. This code block below shows how:

...

button = interactions.Button(style=interactions.ButtonStyle.PRIMARY,label="hello world!",custom_id="hello"

)menu = interactions.SelectMenu(

(continues on next page)

2.1. Quickstart 7

Page 12: PAGES - Read the Docs

discord-interactions, Release 4.0.0

(continued from previous page)

options=[interactions.SelectOption(label="Option one", value="o-one"),interactions.SelectOption(label="Option two", value="o-two"),interactions.SelectOption(label="Option three", value="o-three")

])row = interactions.ActionRow(

components=[button, menu])

...

@bot.command(...)async def test(ctx):

await ctx.send("rows!", components=row)

By default, the components keyword-argument field in the context sending method will always support ActionRow-less sending: you only need to declare rows whenever you need or want to. This field will also support raw arrays andtables, if you so wish to choose to not use our class objects instead.

2.2 API Reference

This page outlines the API wrapper of discord-interactions.

Warning: As of the time of this writing, version 4.0 of discord-interactions has not yet been released, which thisdocumentation currently reflects. The documentation written here is subject to change and is not finalized.

2.2.1 Interactions

Bot Client

class interactions.client.Client(token: str, intents:Optional[Union[interactions.api.models.intents.Intents,List[interactions.api.models.intents.Intents]]] = Intents.DEFAULT,disable_sync: Optional[bool] = None)

A class representing the client connection to Discord’s gateway and API via. WebSocket and HTTP.

Variables• loop (AbstractEventLoop) – The main overall asynchronous coroutine loop in effect.

• listener (Listener) – An instance of interactions.api.dispatch.Listener.

• intents (Optional[Union[Intents, List[Intents]]]) – The application’s intentsas interactions.api.models.Intents.

• http (Request) – An instance of interactions.api.http.Request.

• websocket (WebSocket) – An instance of interactions.api.gateway.WebSocket.

• token (str) – The application token.

8 Chapter 2. Where do I start?

Page 13: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async login(token: str)→ NoneMakes a login with the Discord API.

Parameters token (str) – The application token needed for authorization.

start()→ NoneStarts the client session.

async synchronize(payload: interactions.models.command.ApplicationCommand, permissions:Optional[Union[dict, List[dict]]])→ None

Synchronizes the command specified by checking through the currently registered application commandson the API and modifying if there is a detected chagne in structure.

Warning: This internal call does not need to be manually triggered, as it will automatically be donefor you. Additionally, this will not delete unused commands for you.

Parameters• payload (ApplicationCommand) – The payload/object of the command.

• permissions (Optional[Union[dict, List[dict]]]) – The permissions of thecommand.

event(coro: Coroutine, name: Optional[str] = None)→ Callable[[...], Any]A decorator for listening to dispatched events from the gateway.

Parameters coro (Coroutine) – The coroutine of the event.

Returns A callable response.

Return type Callable[. . . , Any]

command(*, type: Optional[Union[int, interactions.enums.ApplicationCommandType]] =ApplicationCommandType.CHAT_INPUT, name: Optional[str] = None, description: Optional[str]= None, scope: Optional[Union[int, interactions.api.models.guild.Guild, List[int],List[interactions.api.models.guild.Guild]]] = None, options: Optional[Union[Dict[str, Any],List[Dict[str, Any]], interactions.models.command.Option,List[interactions.models.command.Option]]] = None, default_permission: Optional[bool] = None,permissions: Optional[Union[Dict[str, Any], List[Dict[str, Any]],interactions.models.command.Permission, List[interactions.models.command.Permission]]] =None)→ Callable[[...], Any]

A decorator for registering an application command to the Discord API, as well as being able to listen forINTERACTION_CREATE dispatched gateway events.

Parameters• type? – The type of application command. Defaults to interactions.enums.ApplicationCommandType.CHAT_INPUT() or 1.

• name (Optional[str]) – The name of the application command. This is required butkept optional to follow kwarg rules.

• description? – The description of the application command. This should be left blankif you are not using CHAT_INPUT.

• scope? – The “scope”/applicable guilds the application command applies to.

• options? – The “arguments”/options of an application command. This should be leftblank if you are not using CHAT_INPUT.

2.2. API Reference 9

Page 14: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• default_permission? – The default permission of accessibility for the application com-mand. Defaults to True.

• permissions (Optional[Union[Dict[str, Any], List[Dict[str, Any]],Permission, List[Permission]]]) – The permissions of an application command.

Returns A callable response.

Return type Callable[. . . , Any]

component(component: Union[interactions.models.component.Button,interactions.models.component.SelectMenu])→ Callable[[...], Any]

A decorator for handling interaction responses to components.

Parameters component (Union[Button, SelectMenu]) – The component you wish to call-back for.

Returns A callable response.

Return type Callable[. . . , Any]

autocomplete(name: str)→ Callable[[...], Any]A decorator for handling autocompletion fields with commands.

Parameters name (str) – The name of the option to autocomplete.

Returns A callable response.

Return type Callable[. . . , Any]

async raw_socket_create(data: Dict[Any, Any])→ Dict[Any, Any]This is an internal function that takes any gateway socket event and then returns the data purely basedd offof what it does in the client instantiation class.

Parameters data (Dict[Any, Any]) – The data that is returned

Returns A dictionary of raw data.

Return type Dict[Any, Any]

async raw_guild_create(guild)→ NoneThis is an internal function that caches the guild creates on ready.

Parameters guild (Guild) – The guild object data in question.

Event Context

class interactions.context.Context(**kwargs)The base class of "context" for dispatched event data from the gateway.

Variables• message (Message) – The message data model.

• author (Member) – The member data model.

• user (User) – The user data model.

• channel (Channel) – The channel data model.

• guild (Guild) – The guild data model.

• *args – Multiple arguments of the context.

• **kwargs – Keyword-only arguments of the context.

10 Chapter 2. Where do I start?

Page 15: PAGES - Read the Docs

discord-interactions, Release 4.0.0

class interactions.context.InteractionContext(**kwargs)This is a derivation of the base Context class designed specifically for interaction data.

Variables• id (str) – The ID of the interaction.

• application_id (str) – The application ID of the interaction.

• type (Union[str, int, InteractionType]) – The type of interaction.

• data (InteractionData) – The application command data.

• guild_id (str) – The guild ID the interaction falls under.

• channel_id (str) – The channel ID the interaction was instantiated from.

• token (str) – The token of the interaction response.

• responded (bool) – Whether an original response was made or not.

• deferred (bool) – Whether the response was deferred or not.

async defer(ephemeral: Optional[bool] = None)→ NoneThis “defers” an interaction response, allowing up to a 15-minute delay between invokation and responding.

Parameters ephemeral (Optional[bool]) – Whether the deferred state is hidden or not.

async send(content: Optional[str] = None, *, tts: Optional[bool] = None, embeds:Optional[Union[interactions.api.models.message.Embed,List[interactions.api.models.message.Embed]]] = None, allowed_mentions:Optional[interactions.api.models.message.MessageInteraction] = None, message_reference:Optional[interactions.api.models.message.MessageReference] = None, components:Optional[Union[List[Dict[str, Any]], interactions.models.component.ActionRow,interactions.models.component.Button, interactions.models.component.SelectMenu]] = None,sticker_ids: Optional[Union[str, List[str]]] = None, type: Optional[Union[int,interactions.enums.InteractionCallbackType]] = None, ephemeral: Optional[bool] = None)→interactions.api.models.message.Message

This allows the invokation state described in the “context” to send an interaction response.

Parameters• content (Optional[str]) – The contents of the message as a string or string-converted

value.

• tts (Optional[bool]) – Whether the message utilizes the text-to-speech Discord pro-gramme or not.

• embeds (Optional[Union[Embed, List[Embed]]]) – An embed, or list of embedsfor the message.

• allowed_mentions (Optional[MessageInteraction]) – The message interac-tions/mention limits that the message can refer to.

• message_reference (Optional[MessageReference]) – The message to “refer” if at-tempting to reply to a message.

• components (Optional[Union[Component, List[Component]]]) – A component,or list of components for the message.

• sticker_ids (Optional[Union[str, List[str]]]) – A singular or list of IDs tostickers that the application has access to for the message.

• type (Optional[Union[int, InteractionCallbackType]]) – The type of messageresponse if used for interactions or components.

2.2. API Reference 11

Page 16: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• ephemeral (Optional[bool]) – Whether the response is hidden or not.

Returns The sent message as an object.

Return type Message

async edit(content: Optional[str] = None, *, tts: Optional[bool] = None, embeds:Optional[Union[interactions.api.models.message.Embed,List[interactions.api.models.message.Embed]]] = None, allowed_mentions:Optional[interactions.api.models.message.MessageInteraction] = None, message_reference:Optional[interactions.api.models.message.MessageReference] = None, components:Optional[Union[interactions.models.component.ActionRow,interactions.models.component.Button, interactions.models.component.SelectMenu]] = None,sticker_ids: Optional[Union[str, List[str]]] = None)→interactions.api.models.message.Message

This allows the invocation state described in the “context” to send an interaction response. This inheritsthe arguments of the .send() method.

:inherit:`interactions.context.InteractionContext.send()` :return: The edited message as an object.:rtype: Message

async delete()→ NoneThis deletes the interaction response of a message sent by the contextually derived information from thisclass.

Note: Doing this will proceed in the context message no longer being present.

class interactions.context.ComponentContext(**kwargs)This is a derivation of the base Context class designed specifically for component data.

Variables• custom_id (str) – The customized ID for the component to call.

• type (typing.Union[str, int, interactions.enums.ComponentType]) – Thetype of component.

• values (list) – The curated list of values under the component. This will be None if thetype is not SELECT_MENU.

• origin (bool) – Whether this is the origin of the component.

class interactions.context.AutocompleteContext(**kwargs)This is a derivation of the base Context class designed specifically for autocomplete data.

async populate(*, choices: Union[interactions.models.command.Choice,List[interactions.models.command.Choice]])→List[interactions.models.command.Choice]

This “populates” the list of choices that the client-end user will be able to select from in the autocompletefield.

Warning: Only a maximum of 25 choices may be presented within an autocomplete option.

Parameters choices (Union[Choice, List[Choice]]) – The choices you wish to present.

Returns The list of choices you’ve given.

Return type List[Choice]

12 Chapter 2. Where do I start?

Page 17: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Interaction Models

Application Command Models

class interactions.models.command.Choice(**kwargs)A class object representing the choice of an option.

Note: value allows float as a passable value type, whereas it’s supposed to be double.

Variables• name (str) – The name of the choice.

• value (Union[str, int, float]) – The returned value of the choice.

class interactions.models.command.Option(**kwargs)A class object representing the option of an application command.

Note: options is only present for when a subcommand has been established.

Variables• type (OptionType) – The type of option.

• name (str) – The name of the option.

• description (str) – The description of the option.

• focused (bool) – Whether the option is currently being autocompleted or not.

• required? (bool) – Whether the option has to be filled out.

• value? (Optional[str]) – The value that’s currently typed out, if autocompleting.

• choices? (Optional[List[Choice]]) – The list of choices to select from.

• options? (Optional[List[Option]]) – The list of subcommand options included.

• channel_types? (Optional[List[ChannelType]) – Restrictive shown channel types,if given.

class interactions.models.command.Permission(**kwargs)A class object representing the permission of an application command.

Variables• id (int) – The ID of the permission.

• type (PermissionType) – The type of permission.

• permission (bool) – The permission state. True for allow, False for disallow.

class interactions.models.command.ApplicationCommand(**kwargs)A class object representing all types of commands.

Variables• id (int) – The ID of the application command.

• type (ApplicationCommandType) – The application command type.

2.2. API Reference 13

Page 18: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• application_id? (Optional[int]) – The general application ID of the command itself.

• guild_id? (Optional[int]) – The guild ID of the application command.

• name (str) – The name of the application command.

• description (str) – The description of the application command.

• options? (Optional[List[Option]]) – The “options”/arguments of the applicationcommand.

• default_permission? (Optional[bool]) – The default permission accessibility state ofthe application command.

• version (int) – The Application Command version autoincrement identifier.

Component Models

class interactions.models.component.SelectOption(**kwargs)A class object representing the select option of a select menu.

Variables• label (str) – The label of the select option.

• value (str) – The returned value of the select option.

• description? (Optional[str]) – The description of the select option.

• emoji? (Optional[Emoji]) – The emoji used alongside the label of the select option.

• default? (Optional[bool]) – Whether the select option is the default for the select menu.

class interactions.models.component.SelectMenu(**kwargs)A class object representing the select menu of a component.

Variables• type (ComponentType) – The type of select menu. Always defaults to 3.

• custom_id (str) – The customized “ID” of the select menu.

• options (List[SelectOption]) – The list of select options in the select menu.

• placeholder? (Optional[str]) – The placeholder of the select menu.

• min_values? (Optional[int]) – The minimum “options”/values to choose from the com-ponent.

• max_values? (Optional[int]) – The maximum “options”/values to choose from thecomponent.

• disabled? (Optional[bool]) – Whether the select menu is unable to be used.

class interactions.models.component.Button(**kwargs)A class object representing the button of a component.

Variables• type (ComponentType) – The type of button. Always defaults to 2.

• style (ButtonStyle) – The style of the button.

• label (str) – The label of the button.

• emoji? (Optional[Emoji]) – The emoji used alongside the laebl of the button.

14 Chapter 2. Where do I start?

Page 19: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• custom_id? (Optional[str]) – The customized “ID” of the button.

• url? (Optional[str]) – The URL route/path of the button.

• disabled? (Optional[bool]) – Whether the button is unable to be used.

class interactions.models.component.Component(**kwargs)A class object representing the component in an interaction response/followup.

Note: components is only applicable if an ActionRow is supported, otherwise ActionRow-less will be opted.list is in reference to the class.

Variables• type (Union[ActionRow, Button, Menu]) – The type of component.

• custom_id? (Optional[str]) – The customized “ID” of the component.

• disabled? (Optional[bool]) – Whether the component is unable to be used.

• style? (Optional[ButtonStyle]) – The style of the component.

• label? (Optional[str]) – The label of the component.

• emoji? (Optional[Emoji]) – The emoji used alongside the label of the component.

• url? (Optional[str]) – The URl route/path of the component.

• options? (Optional[List[SelectMenu]]) – The “choices”/options of the component.

• placeholder? (Optional[str]) – The placeholder text/value of the component.

• min_values? (Optional[int]) – The minimum “options”/values to choose from the com-ponent.

• max_values? (Optional[int]) – The maximum “options”/values to choose from thecomponent.

• components? (Optional[Union[list, ActionRow, List[ActionRow], Button,List[Button], SelectMenu, List[SelectMenu]]]) – A list of components nestedin the component.

class interactions.models.component.ActionRow(**kwargs)A class object representing the action row for interaction responses holding components.

Note: A message cannot have more than 5 ActionRow’s supported. An ActionRow may also support only 1text input component only.

Variables• type (int) – The type of component. Always defaults to 1.

• components? (Optional[Union[Component, List[Component]]]) – A list of com-ponents the ActionRow has, if any.

2.2. API Reference 15

Page 20: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Miscellaneous Models

class interactions.models.misc.InteractionResolvedDataA class representing the resolved information of an interaction data.

Variables• users (Dict[Union[str, int], User]) – The resolved users data.

• members (Dict[Union[str, int], Member]) – The resolved members data.

• roles (Dict[Union[str, int], Role]) – The resolved roles data.

• channels (Dict[Union[str, int], Channel]) – The resolved channels data.

• messages (Dict[Union[str, int], Message]) – The resolved messages data.

class interactions.models.misc.InteractionData(**kwargs)A class object representing the data of an interaction.

Variables• id (str) – The ID of the interaction data.

• name (str) – The name of the interaction.

• type (ApplicationCommandType) – The type of command from the interaction.

• resolved? (Optional[InteractionResolvedData]) – The resolved version of the data.

• options? (Optional[Union[Option, List[Option]]]) – The options of the interac-tion.

• custom_id? (Optional[str]) – The custom ID of the interaction.

• component_type? (Optional[int]) – The type of component from the interaction.

• values? (Optional[Union[SelectOption, List[SelectOption]]]) – The valuesof the selected options in the interaction.

• target_id? (Optional[str]) – The targeted ID of the interaction.

class interactions.models.misc.Interaction(**kwargs)A class object representing an interaction.

Variables• id (str) – The ID of the interaction.

• application_id (str) – The application’s ID of the interaction.

• type (InteractionType) – The type of interaction.

• data? (Optional[InteractionData]) – The data of the interaction.

• guild_id? (Optional[str]) – The guild ID of the interaction.

• channel_id? (Optional[str]) – The channel ID of the interaction.

• member? (Optional[Member]) – The member who invoked the interaction.

• user? (Optional[User]) – The user who invoked the interaction.

• token (str) – The token of the interaction.

• version – The version of the interaction as an autoincrement identifier.

• message? (Optional[Message]) – The message of the interaction.

16 Chapter 2. Where do I start?

Page 21: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Enumerable Objects

class interactions.enums.ApplicationCommandType(value)An enumerable object representing the types of application commands.

class interactions.enums.InteractionType(value)An enumerable object representing the types of interactions.

class interactions.enums.InteractionCallbackType(value)An enumerable object representing the callback types of interaction responses.

class interactions.enums.OptionType(value)Enumerable object of literal integers holding equivocal values of a slash command’s option(s).

Note: Equivalent of ApplicationCommandOptionType in the Discord API.

classmethod from_type(_type: type)→ enum.IntEnumGet a specific enumerable from a type or object.

Parameters _type (type) – The type or object to get an enumerable integer for.

Returns enum.IntEnum.

class interactions.enums.PermissionType(value)Enumerable object of literal integers holding equivocal values of a slash command’s permission(s).

Note: Equivalent of ApplicationCommandPermissionType in the Discord API.

classmethod from_type(_type: type)→ enum.IntEnumGet a specific enumerable from a type or object. :param _type: The type or object to get an enumerableinteger for. :type _type: type :return: enum.IntEnum.

class interactions.enums.ComponentType(value)Enumerable object of literal integers holding equivocal values of a component(s) type.

Note: Equivalent of Component Types in the Discord API.

class interactions.enums.ButtonStyle(value)An enumerable object representing the styles of button components.

2.2.2 Discord API

Gateway

class interactions.api.gateway.Heartbeat(ws: Any, interval: int)A class representing a consistent heartbeat connection with the gateway.

Variables• ws (WebSocket) – The WebSocket class to infer on.

• interval (Union[int, float]) – The heartbeat interval determined by the gateway.

• event (Event) – The multi-threading event.

2.2. API Reference 17

Page 22: PAGES - Read the Docs

discord-interactions, Release 4.0.0

run()→ NoneStarts the heartbeat connection.

stop()→ NoneStops the heartbeat connection.

class interactions.api.gateway.WebSocket(intents: interactions.api.models.intents.Intents, session_id:Optional[int] = None, sequence: Optional[int] = None)

A class representing a websocket connection with the gateway.

Variables• intents (Intents) – An instance of interactions.api.models.Intents.

• loop (AbstractEventLoop) – The coroutine event loop established on.

• req (Request) – An instance of interactions.api.http.Request.

• dispatch (Listener) – An instance of interactions.api.dispatch.Listener.

• session (Any) – The current client session.

• session_id (int) – The current ID of the gateway session.

• sequence (int) – The current sequence of the gateway connection.

• keep_alive (Heartbeat) – An instance of interactions.api.gateway.Heartbeat.

• closed (bool) – The current connection state.

• http (HTTPClient) – The internal HTTP client used to connect to the gateway.

• options (dict) – The websocket connection options.

async recv()→ Optional[Any]Receives packets sent from the gateway.

async connect(token: str)→ NoneEstablishes a connection to the gateway.

Parameters token (str) – The token to use for identifying.

handle(event: str, data: dict)→ NoneHandles the dispatched event data from a gateway event.

Parameters• event (str) – The name of the event.

• data (dict) – The data of the event.

contextualize(data: dict)→ objectTakes raw data given back from the gateway and gives “context” based off of what it is.

Parameters data (dict) – The data from the gateway.

Returns The context object.

Return type object

async identify()→ NoneSends an IDENTIFY packet to the gateway.

async resume()→ NoneSends a RESUME packet to the gateway.

async heartbeat()→ NoneSends a HEARTBEAT packet to the gateway.

18 Chapter 2. Where do I start?

Page 23: PAGES - Read the Docs

discord-interactions, Release 4.0.0

HTTP Client

class interactions.api.http.Route(method: str, path: str, **kwargs)A class representing how an HTTP route is structured.

Variables• __api__ (ClassVar[str]) – The HTTP route path.

• method (str) – The HTTP method.

• path (str) – The URL path.

• channel_id (Optional[str]) – The channel ID from the bucket if given.

• guild_id (Optional[str]) – The guild ID from the bucket if given.

property bucket: strReturns the route’s bucket.

Returns The route bucket.

Return type str

class interactions.api.http.Padlock(lock: asyncio.locks.Lock)A class representing ratelimited sessions as a “locked” event.

Variables• lock (Lock) – The lock coroutine event.

• keep_open (bool) – Whether the lock should stay open or not.

click()→ NoneRe-closes the lock after the instiantiation and invocation ends.

class interactions.api.http.Request(token: str)A class representing how HTTP requests are sent/read.

Variables• token (str) – The current application token.

• loop (AbstractEventLoop) – The current coroutine event loop.

• ratelimits (dict) – The current ratelimits from the Discord API.

• headers (dict) – The current headers for an HTTP request.

• session (ClientSession) – The current session for making requests.

• lock (Event) – The ratelimit lock event.

check_session()→ NoneEnsures that we have a valid connection session.

async request(route: interactions.api.http.Route, **kwargs)→ Optional[Any]Sends a request to the Discord API.

Parameters• route (Route) – The HTTP route to request.

• **kwargs (dict) – Optional keyword-only arguments to pass as information in the request.

Returns The contents of the request if any.

Return type Optional[Any]

2.2. API Reference 19

Page 24: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async close()→ NoneCloses the current session.

class interactions.api.http.HTTPClient(token: str)A WIP class that represents the http Client that handles all major endpoints to Discord API.

async get_gateway()→ strThis calls the Gateway endpoint and returns a v9 gateway link with JSON encoding.

async get_bot_gateway()→ Tuple[int, str]This calls the BOT Gateway endpoint. :return: A tuple denoting (shard, gateway_url), url from API v9 andJSON encoding

async login()→ Optional[dict]This ‘logins’ to the gateway, which makes it available to use any other endpoint.

async logout()→ NoneThis ‘log outs’ the session.

async get_current_bot_information()→ dictReturns the bot user application object without flags.

async get_current_authorisation_information()→ dictReturns info about the current authorization of the bot user

async get_voice_regions()→ List[interactions.api.models.voice.VoiceRegion]Gets a list from the API a list of voice regions. :return: An array of Voice Region objects.

async get_self()→ dictAn alias to get_user, but only gets the current bot user.

:return A partial User object of the current bot user in the form of a dictionary.

async get_user(user_id: Optional[int] = None)→ dictGets a user object for a given user ID. :param user_id: A user snowflake ID. If omitted, this defaults to thecurrent bot user. :return A partial User object in the form of a dictionary.

async modify_self(payload: dict)→ dictModify the bot user account settings. :param payload: The data to send.

async modify_self_nick_in_guild(guild_id: int, nickname: Optional[str])Changes a nickname of the current bot user in a guild.

Parameters• guild_id – Guild snowflake ID.

• nickname – The new nickname, if any.

Returns Nothing needed to be yielded.

async create_dm(recipient_id: int)→ dictCreates a new DM channel with a user. :param recipient_id: User snowflake ID. :return: Returns a dictio-nary representing a DM Channel object.

async send_message(channel_id: int, content: str, tts: bool = False, embed:Optional[interactions.api.models.message.Embed] = None, nonce:Optional[Union[int, str]] = None, allowed_mentions=None, message_reference:Optional[interactions.api.models.message.Message] = None)

A higher level implementation of create_message() that handles the payload dict internally. Does notintegrate components into the function, and is a port from v3.0.0

async create_message(payload: dict, channel_id: int)→ dictSend a message to the specified channel.

20 Chapter 2. Where do I start?

Page 25: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Parameters• payload – Dictionary contents of a message. (i.e. message payload)

• channel_id – Channel snowflake ID.

Return dict Dictionary representing a message (?)

async get_message(channel_id: int, message_id: int)→ Optional[dict]Get a specific message in the channel. :param channel_id: the channel this message belongs to :parammessage_id: the id of the message :return: message if it exists.

async delete_message(channel_id: int, message_id: int, reason: Optional[str] = None)→ NoneDeletes a message from a specified channel :param channel_id: Channel snowflake ID. :param message_id:Message snowflake ID. :param reason: Optional reason to show up in the audit log. Defaults to None.

async delete_messages(channel_id: int, message_ids: List[int], reason: Optional[str] = None)→ NoneDeletes messages from a specified channel :param channel_id: Channel snowflake ID. :param message_ids:An array of message snowflake IDs. :param reason: Optional reason to show up in the audit log. Defaultsto None.

async edit_message(channel_id: int, message_id: int, payload: dict)→ dictEdits a message that already exists.

Parameters• channel_id – Channel snowflake ID.

• message_id – Message snowflake ID.

• payload (dict) – Any new data that needs to be changed.

Returns A message object with edited attributes.

async pin_message(channel_id: int, message_id: int)→ NonePin a message to a channel. :param channel_id: Channel ID snowflake. :param message_id: Message IDsnowflake.

async unpin_message(channel_id: int, message_id: int)→ NoneUnpin a message to a channel :param channel_id: Channel ID snowflake. :param message_id: Message IDsnowflake.

async publish_message(channel_id: int, message_id: int)→ dictPublishes (API calls it crossposts) a message in a News channel to any that is followed by.

Parameters• channel_id – Channel the message is in

• message_id – The id of the message to publish

Returns message object

async get_self_guilds()→ listGets all guild objects associated with the current bot user.

:return a list of partial guild objects the current bot user is a part of.

async get_guild(guild_id: int)Requests an individual guild from the API. :param guild_id: The guild snowflake ID associated. :return:The guild object associated, if any.

async get_guild_preview(guild_id: int)→ interactions.api.models.guild.GuildPreviewGet a guild’s preview. :param guild_id: Guild ID snowflake. :return: Guild Preview object associated withthe snowflake

2.2. API Reference 21

Page 26: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async modify_guild(guild_id: int, payload: dict, reason: Optional[str] = None)→ NoneModifies a guild’s attributes.

..note:: This only sends the payload. You will have to check it when a higher-level function calls this.

Parameters• guild_id – Guild ID snowflake.

• payload – The parameters to change.

• reason – Reason to send to the audit log, if given.

async leave_guild(guild_id: int)→ NoneLeaves a guild.

Parameters guild_id – The guild snowflake ID associated.

Returns None

async delete_guild(guild_id: int)→ NoneDeletes a guild.

Parameters guild_id – Guild ID snowflake.

async get_guild_widget(guild_id: int)→ dictReturns the widget for the guild. :param guild_id: Guild ID snowflake. :return: Guild Widget contents asa dict: {“enabled”:bool, “channel_id”: str}

async get_guild_widget_settings(guild_id: int)→ dictGet guild widget settings.

Parameters guild_id – Guild ID snowflake.

Returns Guild Widget contents as a dict: {“enabled”:bool, “channel_id”: str}

async get_guild_widget_image(guild_id: int, style: Optional[str] = None)→ strGet a url representing a png image widget for the guild. ..note:

See _<https://discord.com/developers/docs/resources/guild#get-guild-widget-→˓image> for list of styles.

Parameters• guild_id – Guild ID snowflake.

• style – The style of widget required, if given.

Returns A url pointing to this image

async modify_guild_widget(guild_id: int, payload: dict)→ dictModify a guild widget.

Parameters• guild_id – Guild ID snowflake.

• payload – Payload containing new widget attributes.

Returns Updated widget attributes.

async get_guild_invites(guild_id: int)→ List[interactions.api.models.guild.Invite]Retrieves a list of invite objects with their own metadata. :param guild_id: Guild ID snowflake. :return: Alist of invite objects

22 Chapter 2. Where do I start?

Page 27: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async get_guild_welcome_screen(guild_id: int)→ interactions.api.models.guild.WelcomeScreenRetrieves from the API a welcome screen associated with the guild :param guild_id: Guild ID snowflake.:return: Welcome Screen object

async modify_guild_welcome_screen(guild_id: int, enabled: bool, welcome_channels: List[int],description: str)→ interactions.api.models.guild.WelcomeScreen

Modify the guild’s welcome screen.

Parameters• guild_id – Guild ID snowflake.

• enabled – Whether the welcome screen is enabled or not.

• welcome_channels – The new channels (by their ID) linked in the welcome screen andtheir display options

• description – The new server description to show in the welcome screen

Returns Updated Welcome screen object.

async get_guild_integrations(guild_id: int)→ List[dict]Gets a list of integration objects associated with the Guild from the API. :param guild_id: Guild IDsnowflake. :return: An array of integration objects

async delete_guild_integration(guild_id: int, integration_id: int)→ NoneDeletes an integration from the guild. :param guild_id: Guild ID snowflake. :param integration_id: Inte-gration ID snowflake.

async modify_current_user_voice_state(guild_id: int, channel_id: int, suppress: Optional[bool] =None, request_to_speak_timestamp: Optional[str] = None)→ None

Update the current user voice state.

Parameters• guild_id – Guild ID snowflake.

• channel_id – Voice channel ID snowflake.

• suppress – Toggle the user’s suppress state, if given.

• request_to_speak_timestamp – Sets the user’s request to speak, if given.

async modify_user_voice_state(guild_id: int, user_id: int, channel_id: int, suppress: Optional[bool] =None)→ None

Modify the voice state of a user.

Parameters• guild_id – Guild ID snowflake.

• user_id – User ID snowflake.

• channel_id – Voice channel ID snowflake.

• suppress – Toggles the user’s suppress state, if given.

async create_guild_from_guild_template(template_code: str, name: str, icon: Optional[str] = None)→ interactions.api.models.guild.Guild

Create a a new guild based on a template.

..note:: This endpoint can only be used by bots in less than 10 guilds.

Parameters

2.2. API Reference 23

Page 28: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• template_code – The code of the template to use.

• name – The name of the guild (2-100 characters)

• icon – Guild icon URI, if given.

Returns The newly created guild object.

async get_guild_templates(guild_id: int)→ List[interactions.api.models.guild.GuildTemplate]Returns an array of guild templates.

Parameters guild_id – Guild ID snowflake.

Returns An array of guild templates

async create_guild_template(guild_id: int, name: str, description: Optional[str] = None)→interactions.api.models.guild.GuildTemplate

Create a guild template for the guild.

Parameters• guild_id – Guild ID snowflake.

• name – The name of the template

• description – The description of the template, if given.

Returns The created guild template

async sync_guild_template(guild_id: int, template_code: str)→interactions.api.models.guild.GuildTemplate

Sync the template to the guild’s current state.

Parameters• guild_id – Guild ID snowflake.

• template_code – The code for the template to sync

Returns The updated guild template.

async modify_guild_template(guild_id: int, template_code: str, name: Optional[str] = None,description: Optional[str] = None)→interactions.api.models.guild.GuildTemplate

Modify a guild template.

Parameters• guild_id – Guild ID snowflake.

• template_code – Template ID.

• name – The name of the template

• description – The description of the template

Returns The updated guild template

async delete_guild_template(guild_id: int, template_code: str)→interactions.api.models.guild.GuildTemplate

Delete the guild template.

Parameters• guild_id – Guild ID snowflake.

• template_code – Template ID.

24 Chapter 2. Where do I start?

Page 29: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Returns The deleted template object

async get_all_channels(guild_id: int)→ List[dict]Requests from the API to get all channels in the guild.

Parameters guild_id – Guild Snowflake ID

Returns A list of channels.

async get_all_roles(guild_id: int)→ List[interactions.api.models.role.Role]Gets all roles from a Guild. :param guild_id: Guild ID snowflake :return: An array of Role objects.

async create_guild_role(guild_id: int, data: dict, reason: Optional[str] = None)→interactions.api.models.role.Role

Create a new role for the guild. :param guild_id: Guild ID snowflake. :param data: A dict containingmetadata for the role. :param reason: The reason for this action, if given. :return: Role object

async modify_guild_role_position(guild_id: int, role_id: int, position: int, reason: Optional[str] =None)→ List[interactions.api.models.role.Role]

Modify the position of a role in the guild. :param guild_id: Guild ID snowflake. :param role_id: Role IDsnowflake. :param position: The new position of the associated role. :param reason: The reason for thisaction, if given. :return: List of guild roles with updated hierarchy.

async modify_guild_role(guild_id: int, role_id: int, data: dict, reason: Optional[str] = None)→interactions.api.models.role.Role

Modify a given role for the guild. :param guild_id: Guild ID snowflake. :param role_id: Role ID snowflake.:param data: A dict containing updated metadata for the role. :param reason: The reason for this action, ifgiven. :return: Updated role object.

async delete_guild_role(guild_id: int, role_id: int, reason: Optional[str] = None)→ NoneDelete a guild role. :param guild_id: Guild ID snowflake. :param role_id: Role ID snowflake. :paramreason: The reason for this action, if any.

async create_guild_kick(guild_id: int, user_id: int, reason: Optional[str] = None)→ NoneKicks a person from the guild.

Parameters• guild_id – Guild ID snowflake

• user_id – User ID snowflake

• reason – Optional Reason argument.

async create_guild_ban(guild_id: int, user_id: int, delete_message_days: Optional[int] = 0, reason:Optional[str] = None)→ None

Bans a person from the guild, and optionally deletes previous messages sent by them. :param guild_id:Guild ID snowflake :param user_id: User ID snowflake :param delete_message_days: Number of days todelete messages, from 0 to 7. Defaults to 0 :param reason: Optional reason to ban.

async remove_guild_ban(guild_id: int, user_id: int, reason: Optional[str] = None)→ NoneUnbans someone using the API. :param guild_id: Guild ID snowflake :param user_id: User ID snowflake:param reason: Optional reason to unban.

async get_guild_bans(guild_id: int)→ List[dict]Gets a list of banned users. :param guild_id: Guild ID snowflake. :return: A list of banned users.

async get_user_ban(guild_id: int, user_id: int)→ Optional[dict]Gets an object pertaining to the user, if it exists. Returns a 404 if it doesn’t. :param guild_id: Guild IDsnowflake :param user_id: User ID snowflake. :return: Ban object if it exists.

2.2. API Reference 25

Page 30: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async add_guild_member(guild_id: int, user_id: int, access_token: str, nick: Optional[str] = None, roles:Optional[List[interactions.api.models.role.Role]] = None, mute: Optional[bool]= None, deaf: Optional[bool] = None)→interactions.api.models.member.Member

A low level method of adding a user to a guild with pre-defined attributes.

Parameters• guild_id – Guild ID snowflake.

• user_id – User ID snowflake.

• access_token – User access token.

• nick – User’s nickname on join.

• roles – An array of roles that the user is assigned.

• mute – Whether the user is mute in voice channels.

• deaf – Whether the user is deafened in voice channels.

Returns Guild member object (?)

async remove_guild_member(guild_id: int, user_id: int, reason: Optional[str] = None)→ NoneA low level method of removing a member from a guild. This is different from banning them. :paramguild_id: Guild ID snowflake. :param user_id: User ID snowflake. :param reason: Reason to send to auditlog, if any.

async get_guild_prune_count(guild_id: int, days: int = 7, include_roles: Optional[List[int]] = None)→ dict

Retrieves a dict from an API that results in how many members would be pruned given the amount ofdays. :param guild_id: Guild ID snowflake. :param days: Number of days to count. Defaults to 7. :paraminclude_roles: Role IDs to include, if given. :return: A dict denoting {“pruned”: int}

async get_member(guild_id: int, member_id: int)→ Optional[interactions.api.models.member.Member]Uses the API to fetch a member from a guild. :param guild_id: Guild ID snowflake. :param member_id:Member ID snowflake. :return: A member object, if any.

async get_list_of_members(guild_id: int, limit: int = 1, after: Optional[int] = None)→List[interactions.api.models.member.Member]

Lists the members of a guild.

Parameters• guild_id – Guild ID snowflake

• limit – How many members to get from the API. Max is 1000. Defaults to 1.

• after – Get Member IDs after this snowflake. Defaults to None.

Returns An array of Member objects.

async search_guild_members(guild_id: int, query: str, limit: int = 1)→List[interactions.api.models.member.Member]

Search a guild for members who’s username or nickname starts with provided string.

Parameters• guild_id – Guild ID snowflake.

• query – The string to search for

• limit – The number of members to return. Defaults to 1.

26 Chapter 2. Where do I start?

Page 31: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async add_member_role(guild_id: int, user_id: int, role_id: int, reason: Optional[str] = None)→ NoneAdds a role to a guild member.

Parameters• guild_id – The ID of the guild

• user_id – The ID of the user

• role_id – The ID of the role to add

• reason – The reason for this action. Defaults to None.

async remove_member_role(guild_id: int, user_id: int, role_id: int, reason: Optional[str] = None)→None

Removes a role to a guild member.

Parameters• guild_id – The ID of the guild

• user_id – The ID of the user

• role_id – The ID of the role to add

• reason – The reason for this action. Defaults to None.

async modify_member(user_id: int, guild_id: int, payload: dict)Edits a member. This can nick them, change their roles, mute/deafen (and its contrary), and moving themacross channels and/or disconnect them

Parameters• user_id – Member ID snowflake.

• guild_id – Guild ID snowflake.

• payload – Payload representing parameters (nick, roles, mute, deaf, channel_id)

Returns ? (modified voice state? not sure)

async get_channel(channel_id: int)→ interactions.api.models.channel.ChannelGets a channel by ID. If the channel is a thread, it also includes thread members (and other thread attributes):param channel_id: Channel ID snowflake. :return: Channel object.

async delete_channel(channel_id: int)→ NoneDeletes a channel.

Parameters channel_id – Channel ID snowflake

async get_channel_messages(channel_id: int, limit: int = 50, around: Optional[int] = None, before:Optional[int] = None, after: Optional[int] = None)→List[interactions.api.models.message.Message]

Get messages from a channel.

..note:: around, before, and after arguments are mutually exclusive.

Parameters• channel_id – Channel ID snowflake.

• limit – How many messages to get. Defaults to 50, the max is 100.

• around – Get messages around this snowflake ID.

• before – Get messages before this snowflake ID.

2.2. API Reference 27

Page 32: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• after – Get messages after this snowflake ID.

Returns An array of Message objects.

async create_channel(guild_id: int, payload: dict, reason: Optional[str] = None)→interactions.api.models.channel.Channel

Creates a channel within a guild.

..note:: This does not handle payload in this method. Tread carefully.

Parameters• guild_id – Guild ID snowflake.

• payload – Payload data.

• reason – Reason to show in audit log, if needed.

Returns Channel object.

async move_channel(guild_id: int, channel_id: int, new_pos: int, parent_id: Optional[int], lock_perms:bool = False, reason: Optional[str] = None)

Moves a channel to a new position.

Parameters• guild_id – Guild ID snowflake.

• channel_id – Channel ID snowflake.

• new_pos – The new channel position.

• parent_id – The category parent ID, if needed.

• lock_perms – Sync permissions with the parent associated with parent_id. Defaults toFalse.

• reason – Reason to display to the audit log, if any.

Returns?

async modify_channel(channel_id: int, data: dict, reason: Optional[str] = None)→interactions.api.models.channel.Channel

Update a channel’s settings. :param channel_id: Channel ID snowflake. :param data: Data representingupdated settings. :param reason: Reason, if any. :return: Channel with updated attributes, if successful.

async get_channel_invites(channel_id: int)→ List[interactions.api.models.guild.Invite]Get the invites for the channel. :param channel_id: Channel ID snowflake. :return: List of invite objects

async create_channel_invite(channel_id: int, data: dict, reason: Optional[str] = None)→interactions.api.models.guild.Invite

Creates an invite for the given channel.

..note:: This method does not handle payload. It just sends it.

Parameters• channel_id – Channel ID snowflake.

• data – Data representing the payload/invite attributes.

• reason – Reason to show in the audit log, if any.

Returns An invite object.

28 Chapter 2. Where do I start?

Page 33: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async delete_invite(invite_code: str, reason: Optional[str] = None)→ dictDelete an invite. :param invite_code: The code of the invite to delete :param reason: Reason to show inthe audit log, if any. :return: The deleted invite object

async edit_channel_permission(channel_id: int, overwrite_id: int, allow: str, deny: str, perm_type: int,reason: Optional[str] = None)→ None

Edits the channel’s permission overwrites for a user or role in a given channel.

Parameters• channel_id – Channel ID snowflake.

• overwrite_id – The ID of the overridden object.

• allow – the bitwise value of all allowed permissions

• deny – the bitwise value of all disallowed permissions

• perm_type – 0 for a role or 1 for a member

• reason – Reason to display in the Audit Log, if given.

async delete_channel_permission(channel_id: int, overwrite_id: int, reason: Optional[str] = None)→None

Deletes a channel permission overwrite for a user or role in a channel.

Parameters• channel_id – Channel ID snowflake.

• overwrite_id – The ID of the overridden object.

• reason – Reason to display in the Audit Log, if given.

async trigger_typing(channel_id: int)→ NonePosts “. . . is typing” in a given channel.

..note: By default, this lib doesn’t use this endpoint, however, this is listed for third-party implementation.

Parameters channel_id – Channel ID snowflake.

async get_pinned_messages(channel_id: int)→ List[interactions.api.models.message.Message]Get all pinned messages from a channel. :param channel_id: Channel ID snowflake. :return: A list ofpinned message objects.

async create_stage_instance(channel_id: int, topic: str, privacy_level: int = 1, reason: Optional[str] =None)→ interactions.api.models.guild.StageInstance

Create a new stage instance.

Parameters• channel_id – Channel ID snowflake.

• topic – The topic of the stage instance. Limited to 1-120 characters.

• privacy_level – The privacy_level of the stage instance (defaults to guild-only “1”).

• reason – The reason for the creating the stage instance, if any.

Returns The new stage instance

async get_stage_instance(channel_id: int)→ interactions.api.models.guild.StageInstanceGet the stage instance associated with a given channel, if it exists.

Parameters channel_id – Channel ID snowflake.

Returns A stage instance.

2.2. API Reference 29

Page 34: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async modify_stage_instance(channel_id: int, topic: Optional[str] = None, privacy_level: Optional[int]= None, reason: Optional[str] = None)→interactions.api.models.guild.StageInstance

Update the fields of a given stage instance.

Parameters• channel_id – Channel ID snowflake.

• topic – The new topic of the stage instance, if given. Limited to 1-120 characters.

• privacy_level – The new privacy_level of the stage instance.

• reason – The reason for the creating the stage instance, if any.

Returns The updated stage instance.

async delete_stage_instance(channel_id: int, reason: Optional[str] = None)→ NoneDelete a stage instance.

Parameters• channel_id – Channel ID snowflake.

• reason – The reason for the creating the stage instance, if any.

async join_thread(thread_id: int)→ NoneHave the bot user join a thread. :param thread_id: The thread to join.

async leave_thread(thread_id: int)→ NoneHave the bot user leave a thread. :param thread_id: The thread to leave.

async add_member_to_thread(thread_id: int, user_id: int)→ NoneAdd another user to a thread. :param thread_id: The ID of the thread :param user_id: The ID of the userto add

async remove_member_from_thread(thread_id: int, user_id: int)→ NoneRemove another user from a thread. :param thread_id: The ID of the thread :param user_id: The ID of theuser to remove

async list_thread_members(thread_id: int)→ List[dict]Get a list of members in the thread. :param thread_id: the id of the thread :return: a list of member objects

async list_public_archived_threads(channel_id: int, limit: Optional[int] = None, before:Optional[int] = None)→ List[dict]

Get a list of archived public threads in a given channel.

Parameters• channel_id – The channel to get threads from

• limit – Optional limit of threads to

• before – Get threads before this Thread snowflake ID

Returns a list of threads

async list_private_archived_threads(channel_id: int, limit: Optional[int] = None, before:Optional[int] = None)→ List[dict]

Get a list of archived private threads in a channel. :param channel_id: The channel to get threads from:param limit: Optional limit of threads to :param before: Get threads before this Thread snowflake ID:return: a list of threads

30 Chapter 2. Where do I start?

Page 35: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async list_joined_private_archived_threads(channel_id: int, limit: Optional[int] = None, before:Optional[int] = None)→ List[dict]

Get a list of archived private threads in a channel that the bot has joined. :param channel_id: The channel toget threads from :param limit: Optional limit of threads to :param before: Get threads before this snowflakeID :return: a list of threads

async list_active_threads(guild_id: int)→ List[dict]List active threads within a guild. :param guild_id: the guild id to get threads from :return: A list of activethreads

async create_thread(channel_id: int, name: str, auto_archive_duration: int, thread_type: Optional[int] =None, invitable: Optional[bool] = None, message_id: Optional[int] = None, reason:Optional[str] = None)→ dict

From a given channel, create a Thread with an optional message to start with..

Parameters• channel_id – The ID of the channel to create this thread in

• name – The name of the thread

• auto_archive_duration – duration in minutes to automatically archive the thread afterrecent activity, can be set to: 60, 1440, 4320, 10080

• thread_type – The type of thread, defaults to public. ignored if creating thread from amessage

• invitable – Boolean to display if the Thread is open to join or private.

• message_id – An optional message to create a thread from.

• reason – An optional reason for the audit log

Returns The created thread

async create_reaction(channel_id: int, message_id: int, emoji: str)→ NoneCreate a reaction for a message. :param channel_id: Channel snowflake ID. :param message_id: Messagesnowflake ID. :param emoji: The emoji to use (format: name:id)

async remove_self_reaction(channel_id: int, message_id: int, emoji: str)→ NoneRemove bot user’s reaction from a message. :param channel_id: Channel snowflake ID. :param message_id:Message snowflake ID. :param emoji: The emoji to remove (format: name:id)

async remove_user_reaction(channel_id: int, message_id: int, emoji: str, user_id: int)→ NoneRemove user’s reaction from a message

Parameters• channel_id – The channel this is taking place in

• message_id – The message to remove the reaction on.

• emoji – The emoji to remove. (format: name:id)

• user_id – The user to remove reaction of.

async remove_all_reactions(channel_id: int, message_id: int)→ NoneRemove all reactions from a message.

Parameters• channel_id – The channel this is taking place in.

• message_id – The message to clear reactions from.

2.2. API Reference 31

Page 36: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async remove_all_reactions_of_emoji(channel_id: int, message_id: int, emoji: str)→ NoneRemove all reactions of a certain emoji from a message. :param channel_id: Channel snowflake ID. :parammessage_id: Message snowflake ID. :param emoji: The emoji to remove (format: name:id)

async get_reactions_of_emoji(channel_id: int, message_id: int, emoji: str)→List[interactions.api.models.user.User]

Gets the users who reacted to the emoji. :param channel_id: Channel snowflake ID. :param message_id:Message snowflake ID. :param emoji: The emoji to get (format: name:id) :return A list of users who sentthat emoji.

async get_sticker(sticker_id: int)→ dictGet a specific sticker. :param sticker_id: The id of the sticker :return: Sticker or None

async list_nitro_sticker_packs()→ listGets the list of sticker packs available to Nitro subscribers. :return: List of sticker packs

async list_guild_stickers(guild_id: int)→ List[dict]Get the stickers for a guild. :param guild_id: The guild to get stickers from :return: List of Stickers or None

async get_guild_sticker(guild_id: int, sticker_id: int)→ dictGet a sticker from a guild. :param guild_id: The guild to get stickers from :param sticker_id: The stickerto get from the guild :return: Sticker or None

async create_guild_sticker(payload: aiohttp.formdata.FormData, guild_id: int, reason: Optional[str]= None)

Create a new sticker for the guild. Requires the MANAGE_EMOJIS_AND_STICKERS permission.:param payload: the payload to send. :param guild_id: The guild to create sticker at. :param reason:The reason for this action. :return: The new sticker data on success.

async modify_guild_sticker(payload: dict, guild_id: int, sticker_id: int, reason: Optional[str] = None)Modify the given sticker. Requires the MANAGE_EMOJIS_AND_STICKERS permission. :param pay-load: the payload to send. :param guild_id: The guild of the target sticker. :param sticker_id: The stickerto modify. :param reason: The reason for this action. :return: The updated sticker data on success.

async delete_guild_sticker(guild_id: int, sticker_id: int, reason: Optional[str] = None)→ NoneDelete the given sticker. Requires the MANAGE_EMOJIS_AND_STICKERS permission. :paramguild_id: The guild of the target sticker. :param sticker_id: The sticker to delete. :param reason: Thereason for this action. :return: Returns 204 No Content on success.

async get_application_command(application_id: int, guild_id: Optional[int] = None)→ List[dict]Get all application commands from an application :param application_id: Application ID snowflake :paramguild_id: Guild to get commands from, if specified. Defaults to global (None) :return: A list of Applicationcommands.

async create_application_command(application_id: int, data: dict, guild_id: Optional[int] = None)Registers to the Discord API an application command.

Parameters• application_id – Application ID snowflake

• data – The dictionary that contains the command (name, description, etc)

• guild_id – Guild ID snowflake to put them in, if applicable.

Returns An application command object.

async overwrite_application_command(application_id: int, data: List[dict], guild_id: Optional[int] =None)→ List[dict]

Overwrites application command(s) from a scope to the new, updated commands.

..note: This applies to all forms of application commands (slash and context menus)

32 Chapter 2. Where do I start?

Page 37: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Parameters• application_id – Application ID snowflake

• data – The dictionary that contains the command (name, description, etc)

• guild_id – Guild ID snowflake to put them in, if applicable.

Returns An array of application command objects.

async edit_application_command(application_id: int, data: dict, command_id: int, guild_id:Optional[int] = None)→ dict

Edits an application command.

Parameters• application_id – Application ID snowflake.

• data – A dictionary containing updated attributes

• command_id – The application command ID snowflake

• guild_id – Guild ID snowflake, if given. Defaults to None/global.

Returns The updated application command object.

async delete_application_command(application_id: int, command_id: int, guild_id: Optional[int] =None)→ None

Deletes an application command.

Parameters• application_id – Application ID snowflake.

• command_id – Application command ID snowflake.

• guild_id – Guild ID snowflake, if declared. Defaults to None (Global).

async edit_application_command_permissions(application_id: int, guild_id: int, command_id: int,data: List[dict])→ dict

Edits permissions for an application command

Parameters• application_id – Application ID snowflake

• guild_id – Guild ID snowflake

• command_id – Application command ID snowflake

• data – Permission data.

Returns Returns an updated Application Guild permission object.

async batch_edit_application_command_permissions(application_id: int, guild_id: int, data:List[dict])→ List[dict]

Edits permissions for all Application Commands in a guild.

Parameters• application_id – Application ID snowflake

• guild_id – Guild ID snowflake

• data – An array of permission dictionaries.

Returns An updated array of application array permissions.

2.2. API Reference 33

Page 38: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async get_application_command_permissions(application_id: int, guild_id: int, command_id: int)→dict

Gets, from the Discord API, permissions from a specific Guild application command.

Parameters• application_id – Application ID snowflake

• guild_id – Guild ID snowflake

• command_id – Application Command ID snowflake

Returns a Guild Application Command permissions object

async get_all_application_command_permissions(application_id: int, guild_id: int)→ List[dict]Gets, from the Discord API, permissions from all Application commands at that Guild.

Parameters• application_id – Application ID snowflake

• guild_id – Guild ID snowflake

Returns An array of Guild Application Command permissions

async create_interaction_response(token: str, application_id: int, data: dict)→ NonePosts initial response to an interaction, but you need to add the token.

Parameters• token – Token.

• application_id – Application ID snowflake

• data – The data to send.

async get_original_interaction_response(token: str, application_id: str, message_id: int ='@original')→ dict

Gets an existing interaction message. :param token: token :param application_id: Application IDsnowflake. :param message_id: Message ID snowflake. Defaults to @original which represents the initialresponse msg. :return: Message data.

async edit_interaction_response(data: dict, token: str, application_id: str, message_id: int ='@original')→ dict

Edits an existing interaction message, but token needs to be manually called. :param data: A dictionary con-taining the new response. :param token: token :param application_id: Application ID snowflake. :parammessage_id: Message ID snowflake. Defaults to @original which represents the initial response msg.:return: Updated message data.

async create_webhook(channel_id: int, name: str, avatar: Optional[Any] = None)→ dictCreate a new webhook. :param channel_id: Channel ID snowflake. :param name: Name of the webhook(1-80 characters) :param avatar: The image for the default webhook avatar, if given.

:return Webhook object

async get_channel_webhooks(channel_id: int)→ List[dict]Return a list of channel webhook objects. :param channel_id: Channel ID snowflake. :return:List of web-hook objects

async get_guild_webhooks(guild_id: int)→ List[dict]Return a list of guild webhook objects. :param guild_id: Guild ID snowflake

Returns List of webhook objects

34 Chapter 2. Where do I start?

Page 39: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async get_webhook(webhook_id: int, webhook_token: Optional[str] = None)→ dictReturn the new webhook object for the given id. :param webhook_id: Webhook ID snowflake. :paramwebhook_token: Webhook Token, if given.

:return:Webhook object

async modify_webhook(webhook_id: int, name: str, avatar: Any, channel_id: int, webhook_token:Optional[str] = None)→ dict

Modify a webhook. :param webhook_id: Webhook ID snowflake :param name: the default name of thewebhook :param avatar: image for the default webhook avatar :param channel_id: Channel ID snowflakeof new destination :param webhook_token: The token for the webhook, if given.

Returns Modified webhook object.

async delete_webhook(webhook_id: int, webhook_token: Optional[str] = None)Delete a webhook :param webhook_id: Webhook ID snowflake. :param webhook_token: The token forthe webhook, if given.

async execute_webhook(webhook_id: int, webhook_token: str, payload: dict, wait: bool = False,thread_id: Optional[int] = None)→Optional[interactions.api.models.message.Message]

Sends a message as a webhook.

Parameters• webhook_id – Webhook ID snowflake.

• webhook_token – The token for the webhook.

• payload – Payload consisting of the message.

• wait – A bool that signifies waiting for server confirmation of a send before responding.

• thread_id – Optional, sends a message to the specified thread.

Returns The message sent, if wait=True, else None.

async execute_slack_webhook(webhook_id: int, webhook_token: str, payload: dict)→ NoneSends a message to a Slack-compatible webhook.

Parameters• webhook_id – Webhook ID snowflake.

• webhook_token – The token for the webhook.

• payload – Payload consisting of the message.

Returns?

Note: Payload structure is different than Discord’s. See here<https://api.slack.com/messaging/webhooks>_ for more details.

async execute_github_webhook(webhook_id: int, webhook_token: str, payload: dict)→ NoneSends a message to a Github-compatible webhook.

Parameters• webhook_id – Webhook ID snowflake.

• webhook_token – The token for the webhook.

2.2. API Reference 35

Page 40: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• payload – Payload consisting of the message.

Returns?

Note: Payload structure is different than Discord’s. See here<https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook>_ formore details.

async get_webhook_message(webhook_id: int, webhook_token: str, message_id: int)→interactions.api.models.message.Message

Retrieves a message sent from a Webhook.

Parameters• webhook_id – Webhook ID snowflake.

• webhook_token – Webhook token.

• message_id – Message ID snowflake,

Returns A Message object.

async edit_webhook_message(webhook_id: int, webhook_token: str, message_id: int, data: dict)→interactions.api.models.message.Message

Edits a message sent from a Webhook.

Parameters• webhook_id – Webhook ID snowflake.

• webhook_token – Webhook token.

• message_id – Message ID snowflake.

• data – A payload consisting of new message attributes.

Returns An updated message object.

async delete_webhook_message(webhook_id: int, webhook_token: str, message_id: int)→ NoneDeletes a message object.

Parameters• webhook_id – Webhook ID snowflake.

• webhook_token – Webhook token.

• message_id – Message ID snowflake.

async get_all_emoji(guild_id: int)→ List[interactions.api.models.message.Emoji]Gets all emojis from a guild.

Parameters guild_id – Guild ID snowflake.

Returns A list of emojis.

async get_guild_emoji(guild_id: int, emoji_id: int)→ interactions.api.models.message.EmojiGets an emote from a guild. :param guild_id: Guild ID snowflake. :param emoji_id: Emoji ID snowflake.:return: Emoji object

36 Chapter 2. Where do I start?

Page 41: PAGES - Read the Docs

discord-interactions, Release 4.0.0

async create_guild_emoji(guild_id: int, data: dict, reason: Optional[str] = None)→interactions.api.models.message.Emoji

Creates an emoji. :param guild_id: Guild ID snowflake. :param data: Emoji parameters. :param reason:Optionally, give a reason. :return: An emoji object with the included parameters.

async modify_guild_emoji(guild_id: int, emoji_id: int, data: dict, reason: Optional[str] = None)→interactions.api.models.message.Emoji

Modifies an emoji. :param guild_id: Guild ID snowflake. :param emoji_id: Emoji ID snowflake :paramdata: Emoji parameters with updated attributes :param reason: Optionally, give a reason. :return: An emojiobject with updated attributes.

async delete_guild_emoji(guild_id: int, emoji_id: int, reason: Optional[str] = None)→ NoneDeletes an emoji. :param guild_id: Guild ID snowflake. :param emoji_id: Emoji ID snowflake :paramreason: Optionally, give a reason.

Client Cache

class interactions.api.cache.Item(id: str, value: Any)A class representing the defined item in a stored dataset.

Variables• id (str) – The ID of the item.

• value (Any) – The item itself.

• type (Type) – The ID type representation.

class interactions.api.cache.StorageA class representing a set of items stored as a cache state.

Variables values (List[Item]) – The list of items stored.

add(item: interactions.api.cache.Item)→ collections.OrderedDictAdds a new item to the storage.

Parameters item (Item) – The item to add.

Returns The item added.

Return type List[Item]

get(id: str)→ Optional[interactions.api.cache.Item]Gets an item from the storage.

Parameters id (str) – The ID of the item.

Returns The item from the storage if any.

Return type Optional[Item]

class interactions.api.cache.CacheA class representing the cache. This cache collects all of the HTTP requests made for the represented instancesof the class.

Variables• dms (Cache) – The cached Direct Messages.

• self_guilds (Cache) – The cached guilds upon gateway connection.

• guilds (Cache) – The cached guilds after ready.

• channels (Cache) – The cached channels of guilds.

2.2. API Reference 37

Page 42: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• roles (Cache) – The cached roles of guilds.

• members (Cache) – The cached members of guilds and threads.

• messages (Cache) – The cached messages of DMs and channels.

• interactions (Cache) – The cached interactions upon interaction.

Enumerable Objects

class interactions.api.enums.DefaultErrorType(value)An enumerable object for the default errors that occur with interaction creation.

Note: This is a port from v3’s errors, which basically delegate errors to a unique error code. This enum’spurpose is to help remember error codes. Importing this class is not required.

i.e. : raise InteractionException(1) == raise InteractionException(REQUEST_FAILURE)

class interactions.api.enums.OpCodeType(value)An enumerable object for the Gateway’s OPCODE result state. This is representative of the OPCodes generatedby the WebSocket.

Note: Equivalent of Gateway Opcodes in the Discord API.

class interactions.api.enums.WSCloseCodeType(value)An enumerable object for the Gateway’s closing connection codes. This is representative of the Gateway re-sponses generated by the WebSocket.

Note: Equivalent of Gateway Close Event Codes in the Discord API.

class interactions.api.enums.HTTPResponseType(value)An enumerable object for the HTTP response codes Discord gives out.

Note: This enumerable does not list the documented 5XX, as it may vary.

class interactions.api.enums.JSONResponseType(value)An enumerable object for the JSON error response codes Discord gives out.

Note: Equivalent of JSON Error Codes in the Discord API.

38 Chapter 2. Where do I start?

Page 43: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Model Objects

Channel Models

class interactions.api.models.channel.ChannelType(value)An enumerable object representing the type of channels.

..note:: While all of them are listed, not all of them will be used at this library’s scope.

class interactions.api.models.channel.ThreadMetadata(**kwargs)A class object representing the metadata of a thread.

Note: invitable will only show if the thread can have an invited created with the current cached permissions.

Variables• archived (bool) – The current thread accessibility state.

• auto_archive_duration (int) – The auto-archive time.

• archive_timestamp (datetime.datetime.timestamp) – The timestamp that the threadwill be/has been closed at.

• locked (bool) – The current message state of the thread.

• invitable (typing.Optional[bool]) – The ability to invite users to the thread.

class interactions.api.models.channel.ThreadMember(**kwargs)A class object representing a member in a thread.

Note: id only shows if there are active intents involved with the member in the thread.

Variables• id (typing.Optional[int]) – The “ID” or intents of the member.

• user_id (int) – The user ID of the member.

• join_timestamp (datetime.datetime.timestamp) – The timestamp of when the mem-ber joined the thread.

• flags (int) – The bitshift flags for the member in the thread.

class interactions.api.models.channel.Channel(**kwargs)A class object representing all types of channels.

Note: The purpose of this model is to be used as a base class, and is never needed to be used directly.

Variables• id (int) – The (snowflake) ID of the channel.

• type (int) – The type of channel.

• guild_id (typing.Optional[int]) – The ID of the guild if it is not a DM channel.

• position (typing.Optional[int]) – The position of the channel.

2.2. API Reference 39

Page 44: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• permission_overwrites (typing.List[interactions.api.models.misc.Overwrite]) – The non-synced permissions of the channel.

• name (str) – The name of the channel.

• topic (typing.Optional[str]) – The description of the channel.

• nsfw (typing.Optional[bool]) – Whether the channel is NSFW.

• last_message_id (int) – The ID of the last message sent.

• bitrate (typing.Optional[int]) – The audio bitrate of the channel.

• user_limit (typing.Optional[int]) – The maximum amount of users allowed in thechannel.

• rate_limit_per_user (typing.Optional[int]) – The concurrent ratelimit for usersin the channel.

• recipients (typing.Optional[typing.List[interactions.api.models.user.User]]) – The recipients of the channel.

• icon (typing.Optional[str]) – The icon of the channel.

• owner_id (typing.Optional[int]) – The owner of the channel.

• application_id (typing.optional[int]) – The application of the channel.

• parent_id (typing.Optional[int]) – The ID of the “parent”/main channel.

• last_pin_timestamp (typing.Optional[datetime.datetime]) – The timestamp ofthe last pinned message in the channel.

• rtc_region (typing.Optional[str]) – The region of the WebRTC connection for thechannel.

• video_quality_mode (typing.Optional[int]) – The set quality mode for videostreaming in the channel.

• message_count (int) – The amount of messages in the channel.

• member_count (typing.Optional[int]) – The amount of members in the channel.

• thread_metadata (typing.Optional[interactions.api.models.channel.ThreadMetadata]) – The thread metadata of the channel.

• member (typing.Optional[interactions.api.models.channel.ThreadMember])– The member of the thread in the channel.

• default_auto_archive_duration (typing.Optional[int]) – The set auto-archivetime for all threads to naturally follow in the channel.

• permissions (typing.Optional[str]) – The permissions of the channel.

40 Chapter 2. Where do I start?

Page 45: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Guild Models

class interactions.api.models.guild.GuildFeature(value)An enumerable string-formatted class representing all of the features a guild can have.

class interactions.api.models.guild.WelcomeChannels(**kwargs)A class object representing a welcome channel on the welcome screen.

Note: emoji_id and emoji_name are given values respectively if the welcome channel uses an emoji.

Variables• channel_id (int) – The ID of the welcome channel.

• description (str) – The description of the welcome channel.

• emoji_id (typing.Optional[int]) – The ID of the emoji of the welcome channel.

• emoji_name (typing.Optional[str]) – The name of the emoji of the welcome channel.

class interactions.api.models.guild.WelcomeScreen(**kwargs)A class object representing the welcome screen shown for community guilds.

Note: description is ambiguous – Discord poorly documented this. :)

We assume it’s for the welcome screen topic.

Variables• description (typing.Optional[str]) – The description of the welcome sceen.

• welcome_channels (typing.List[interactions.api.models.guild.WelcomeChannels]) – A list of welcome channels of the welcome screen.

class interactions.api.models.guild.StageInstance(**kwargs)A class object representing an instace of a stage channel in a guild.

Variables• id (int) – The ID of the stage.

• guild_id (int) – The guild ID the stage is in.

• channel_id (int) – The channel ID the stage is instantiated from.

• topic (str) – The topic of the stage.

• privacy_level (int) – The “privacy”/inclusive accessibility level of the stage.

• discoverable_disabled (bool) – Whether the stage can be seen from the stage discovery.

class interactions.api.models.guild.Guild(**kwargs)A class object representing how a guild is registered.

Note: Most of these optionals are actually declared with their value upon instantiation but are kept like thissince this class object is meant to be more broad and generalized.

Variables

2.2. API Reference 41

Page 46: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• id (int) – The ID of the guild.

• name (str) – The name of the guild.

• icon (typing.Optional[str]) – The icon of the guild.

• icon_hash (typing.Optional[str]) – The hashed version of the icon of the guild.

• splash (typing.Optional[str]) – The invite splash banner of the guild.

• discovery_splash (typing.Optional[str]) – The discovery splash banner of theguild.

• owner (typing.Optional[bool]) – Whether the guild is owned.

• owner_id (int) – The ID of the owner of the guild.

• permissions (typing.Optional[str]) – The permissions of the guild.

• region (typing.Optional[str]) – The geographical region of the guild.

• afk_channel_id (typing.Optional[int]) – The AFK voice channel of the guild.

• afk_timeout (int) – The timeout of the AFK voice channel of the guild.

• widget_enabled (typing.Optional[bool]) – Whether widgets are enabled in the guild.

• widget_channel_id (typing.Optional[int]) – The channel ID of the widget in theguild.

• verification_level (int) – The level of user verification of the guild.

• default_message_notifications (int) – The default message notifications setting ofthe guild.

• explicit_content_filter (int) – The explicit content filter setting level of the guild.

• roles (typing.List[interactions.api.models.role.Role]) – The list of roles inthe guild.

• emojis (typing.List[interactions.api.models.message.Emoji]) – The list ofemojis from the guild.

• features (typing.List[interactions.api.models.guild.GuildFeature]) – Thelist of features of the guild.

• mfa_level (int) – The MFA level of the guild.

• application_id (typing.Optional[int]) – The application ID of the guild.

• system_channel_id (typing.Optional[int]) – The channel ID of the system of theguild.

• rules_channel_id (typing.Optional[int]) – The channel ID of Discord’s defined“rules” channel of the guild.

• joined_at (typing.Optional[datetime.datetime]) – The timestamp the memberjoined the guild.

• large (typing.Optional[bool]) – Whether the guild is considered “large.”

• unavailable (typing.Optional[bool]) – Whether the guild is unavailable to access.

• member_count (typing.Optional[int]) – The amount of members in the guild.

• presences (typing.Optional[typing.List[interactions.api.models.presence.PresenceUpdate]]) – The list of presences in the guild.

42 Chapter 2. Where do I start?

Page 47: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• max_presences (typing.Optional[int]) – The maximum amount of presences allowedin the guild.

• max_members (typing.Optional[int]) – The maximum amount of members allowed inthe guild.

• vanity_url_code (typing.Optional[str]) – The vanity URL of the guild.

• description (typing.Optional[str]) – The description of the guild.

• banner (typing.Optional[str]) – The banner of the guild.

• premium_tier (int) – The server boost level of the guild.

• premium_subscription_count (typing.Optional[int]) – The amount of serverboosters in the guild.

• preferred_locale (str) – The “preferred” local region of the guild.

• public_updates_channel_id (typing.Optional[int]) – The channel ID for commu-nity updates of the guild.

• max_video_channel_users (typing.Optional[int]) – The maximum amount ofvideo streaming members in a channel allowed in a guild.

• approximate_member_count (typing.Optional[int]) – The approximate amount ofmembers in the guild.

• approximate_presence_count (typing.Optional[int]) – The approximate amountof presences in the guild.

• welcome_screen (typing.Optional[interactions.api.models.guild.WelcomeScreen]) – The welcome screen of the guild.

• nsfw_level (int) – The NSFW safety filter level of the guild.

• stage_instances (typing.Optional[interactions.api.models.guild.StageInstance]) – The stage instance of the guild.

• stickers (typing.Optional[typing.List[interactions.api.models.message.Sticker]]) – The list of stickers from the guild.

class interactions.api.models.guild.GuildPreview(**kwargs)A model representing the preview of a guild.

..note:: This refers to the documentation here <https://discord.com/developers/docs/resources/guild>_

Variables• id (int) – The ID of the guild.

• name (str) – The name of the guild.

• icon (typing.Optional[str]) – The icon of the guild.

• splash (typing.Optional[str]) – The invite splash banner of the guild.

• discovery_splash (typing.Optional[str]) – The discovery splash banner of theguild.

• emojis (typing.List[interactions.api.models.message.Emoji]) – The list ofemojis from the guild.

• features (typing.List[interactions.api.models.guild.GuildFeature]) – Thelist of features of the guild.

2.2. API Reference 43

Page 48: PAGES - Read the Docs

discord-interactions, Release 4.0.0

• approximate_member_count (int) – The approximate amount of members in the guild.

• approximate_presence_count (int) – The approximate amount of presences in theguild.

• description (typing.Optional[str]) – The description of the guild.

class interactions.api.models.guild.Invite(**kwargs)The invite object.

class interactions.api.models.guild.GuildTemplate(**kwargs)An object representing the snapshot of an existing guild.

Intents Models

class interactions.api.models.intents.Intents(value)A class objct representing the bitshift flags respective for each intents type.

Note: Equivalent of Gateway Intents in the Discord API.

Member Models

class interactions.api.models.member.Member(**kwargs)A class object representing the member of a guild.

Note: Also known as the guild member class object. (or partial)

The methodology, instead of regular d.py conventions is to do member.user to get the pure User object, insteadof d.py’s option of merging.

pending and permissions only apply for members retroactively requiring to verify rules via. membershipscreening or lack permissions to speak.

Variables• user (interactions.api.models.user.User) – The user of the guild.

• nick (str) – The nickname of the member.

• avatar (Optional[str]) – The hash containing the user’s guild avatar, if applicable.

• roles (List[int]) – The list of roles of the member.

• joined_at (datetime.timestamp) – The timestamp the member joined the guild at.

• premium_since (datetime.datetime) – The timestamp the member has been a serverbooster since.

• deaf (bool) – Whether the member is deafened.

• mute (bool) – Whether the member is muted.

• is_pending (Optional[bool] pending /) – Whether the member is pending to passmembership screening.

• permissions (Optional[str]) – Whether the member has permissions.

44 Chapter 2. Where do I start?

Page 49: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Message Models

class interactions.api.models.message.MessageType(value)An enumerable object representing the types of messages.

..note:: While all of them are listed, not all of them would be used at this lib’s scope.

class interactions.api.models.message.MessageActivity(**kwargs)A class object representing the activity state of a message.

Note: party_id is ambigious – Discord poorly documented this. :)

We assume it’s for game rich presence invites? i.e. : Phasmophobia, Call of Duty

Variables• type (int) – The message activity type.

• party_id (typing.Optional[str]) – The party ID of the activity.

class interactions.api.models.message.MessageReference(**kwargs)A class object representing the “referenced”/replied message.

Note: All of the class instances are optionals because a message can entirely never be referenced.

Variables• message_id (typing.Optional[int]) – The ID of the referenced message.

• channel_id (typing.Optional[int]) – The channel ID of the referenced message.

• guild_id (typing.Optional[int]) – The guild ID of the referenced message.

• fail_if_not_exists (typing.Optional[bool]) – Whether the message reference ex-ists.

class interactions.api.models.message.Attachment(**kwargs)A class object representing an attachment in a message.

Note: height and width have values based off of content_type, which requires it to be a media file withviewabiltiy as a photo, animated photo, GIF and/or video.

Variables• id (int) – The ID of the attachment.

• filename (str) – The name of the attachment file.

• content_type (typing.Optional[str]) – The type of attachment file.

• size (int) – The size of the attachment file.

• url (str) – The CDN URL of the attachment file.

• proxy_url (str) – The proxied/cached CDN URL of the attachment file.

• height (typing.Optional[int]) – The height of the attachment file.

• width (typing.Optional[int]) – The width of the attachment file.

2.2. API Reference 45

Page 50: PAGES - Read the Docs

discord-interactions, Release 4.0.0

class interactions.api.models.message.MessageInteraction(**kwargs)

class interactions.api.models.message.ChannelMention(**kwargs)

class interactions.api.models.message.Message(**kwargs)The big Message model.

The purpose of this model is to be used as a base class, and is never needed to be used directly.

class interactions.api.models.message.Emoji(**kwargs)

class interactions.api.models.message.ReactionObject(**kwargs)

class interactions.api.models.message.PartialSticker(**kwargs)Partial object for a Sticker.

class interactions.api.models.message.Sticker(**kwargs)The full Sticker object.

class interactions.api.models.message.EmbedImageStruct(**kwargs)This is the internal structure denoted for thumbnails, images or videos

class interactions.api.models.message.EmbedProvider(**kwargs)

class interactions.api.models.message.EmbedAuthor(**kwargs)

class interactions.api.models.message.EmbedFooter(**kwargs)

class interactions.api.models.message.EmbedField(**kwargs)

class interactions.api.models.message.Embed(**kwargs)

Miscellanous Models

class interactions.api.models.misc.DictSerializerMixin(**kwargs)The purpose of this mixin is to be subclassed.

..note:

On subclass, it:-- From kwargs (received from the Discord API response), add it to the `_json`␣

→˓attributesuch that it can be reused by other libraries/extensions-- Aids in attributing the kwargs to actual model attributes, i.e. `User.id`

..warning:

This does NOT convert them to its own data types, i.e. timestamps, or User within␣→˓Member. This is left bythe object that's using the mixin.

class interactions.api.models.misc.Overwrite(**kwargs)This is used for the PermissionOverride obj

class interactions.api.models.misc.ClientStatus(**kwargs)

class interactions.api.models.misc.FormatThis object is used to respectively format markdown strings provided by the WYSIWYG text editor for ease-of-accessibility and simple implementations into bots.

46 Chapter 2. Where do I start?

Page 51: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Note: All base strings are given brackets before being f-string parsable to make conversion simplified.

Warning: the stylize() method must be used if you’re actually looking to give a str specific result.

stylize(format: str, **kwargs)→ strThis takes a format style from the object and converts it into a useable string for ease.

Parameters• format (str) – The format string to use.

• **kwargs (dict) – Multiple key-word arguments to use, where key=value is for-mat=value.

Returns str

Presence Models

class interactions.api.models.presence.PresenceActivity(**kwargs)

class interactions.api.models.presence.PresenceUpdate(**kwargs)

Role Models

class interactions.api.models.role.RoleTags(**kwargs)

class interactions.api.models.role.Role(**kwargs)

Team Models

class interactions.api.models.team.TeamMember(**kwargs)

class interactions.api.models.team.Team(**kwargs)

class interactions.api.models.team.Application(**kwargs)

User Models

class interactions.api.models.user.User(**kwargs)

Voice Models

class interactions.api.models.voice.VoiceState(**kwargs)

class interactions.api.models.voice.VoiceRegion(**kwargs)

class interactions.api.models.voice.Voice(**kwargs)

2.2. API Reference 47

Page 52: PAGES - Read the Docs

discord-interactions, Release 4.0.0

Dispatching

class interactions.api.dispatch.ListenerA class representing how events become dispatched and listened to.

Variables• loop (AbstractEventLoop) – The coroutine event loop established on.

• events (dict) – A list of events being dispatched.

dispatch(name: str, *args, **kwargs)→ NoneDispatches an event given out by the gateway.

Parameters• name (str) – The name of the event to dispatch.

• *args (list[Any]) – Multiple arguments of the coroutine.

• **kwargs (dict) – Keyword-only arguments of the coroutine.

register(coro: Coroutine, name: Optional[str] = None)→ NoneRegisters a given coroutine as an event to be listened to. If the name of the event is not given, it will thenbe determined by the coroutine’s name.

i.e. : async def on_guild_create -> “ON_GUILD_CREATE” dispatch.

Parameters• coro (Coroutine) – The coroutine to register as an event.

• name (Optional[str]) – The name to associate the coroutine with. Defaults to None.

Error Exceptions

class interactions.api.error.ErrorFormatterA customized error formatting script to return specific errors.

exception interactions.api.error.InteractionException(_InteractionException__type:Optional[Union[int, enum.IntEnum]] = 0,**kwargs)

An exception class for interactions.

Note: This is a WIP. This isn’t meant to be used yet, this is a baseline, and for extensive testing/review beforeintegration. Likewise, this will show the concepts before use, and will be refined when time goes on.

Variables• _formatter (interactions.api.error.ErrorFormatter) – The built in formatter.

• _lookup (dict) – A dictionary containing the values from the built-in Enum.

static lookup()→ dictFrom the default error enum integer declaration, generate a dictionary containing the phrases used for theerrors.

property type: Optional[Union[int, enum.IntEnum]]Grabs the type attribute. Primarily useful to use it in conditions for integral v4 (potential) logic.

48 Chapter 2. Where do I start?

Page 53: PAGES - Read the Docs

discord-interactions, Release 4.0.0

error()→ NoneThis calls the exception.

exception interactions.api.error.GatewayException(_GatewayException__type, **kwargs)This is a derivation of InteractionException in that this is used to represent Gateway closing OP codes.

Variables• _formatter (ErrorFormatter) – The built in formatter.

• _lookup (dict) – A dictionary containing the values from the built-in Enum.

static lookup()→ dictFrom the default error enum integer declaration, generate a dictionary containing the phrases used for theerrors.

exception interactions.api.error.HTTPException(_HTTPException__type, **kwargs)This is a derivation of InteractionException in that this is used to represent HTTP Exceptions.

Variables• _formatter (ErrorFormatter) – The built in formatter.

• _lookup (dict) – A dictionary containing the values from the built-in Enum.

static lookup()→ dictFrom the default error enum integer declaration, generate a dictionary containing the phrases used for theerrors.

exception interactions.api.error.JSONException(_JSONException__type, **kwargs)This is a derivation of InteractionException in that this is used to represent JSON API Exceptions.

Variables• _formatter (ErrorFormatter) – The built in formatter.

• _lookup (dict) – A dictionary containing the values from the built-in Enum.

static lookup()→ dictFrom the default error enum integer declaration, generate a dictionary containing the phrases used for theerrors.

2.3 Frequently Asked Questions

Got a question about our library? Well, your answer is probably laying somewhere around here.

Note: This page is maintained by the Helpers of the Discord server, and updated by the library developer at theirdiscretion. For any comments, feedback or concerns please consider joining our server and bringing it up in oursupport channels.

Warning: This FAQ list currently reflects v4.0 as of the time of this writing, all other versions are considereddeprecated. Because of this, there will not be any answers for questions regarding v3.0 and below.

2.3. Frequently Asked Questions 49

Page 54: PAGES - Read the Docs

discord-interactions, Release 4.0.0

2.3.1 discord.py is dead! Will this library die too?

The short answer is: no.

The decision to become a standalone library that is now an API wrapper for the Discord API was made before Dannyposted his gist on GitHub about ceasing development of discord.py. This is the official statement from the librarydeveloper regarding this:

2.3.2 Are you going to/will/consider fork(ing) discord.py?

The short answer is: no.

The long answer is a list of numerous reasons as to why this decision was made:

• There are/will be numerous forks out there for discord.py, and because of that, we cannot safely guarantee ourability to help users out who may be using their own form of modified code.

• The original purpose of this library was to act as an extension of discord.py, but due to the issue of constantlyhaving to monkeypatch solutions into their codebase to keep our library working introduced extreme technicaldebt. Forking discord.py and building off of it does not change anything from our issue of avoiding this.

• The goal of this library is to solely implement support and integrate the use of interactions from the Discord API.Making this library unique in a sense that we only do this seemed reasonable and within our margin of standardsat the time.

• The message intent will inevitably be forced as a privileged intent in April 2022. The practicality of trying tosupport message commands will be infeasible since Discord Developers have already admitted that “not wantingto implement application commands” will not be a valid reason for applying for this privileged intent.

• Forking discord.py would be a massive change to our current codebase, throwing away all of the effort we’veput into it so far, and basically just be rewriting how v2.0a was created. That would make it nothing more thandiscord.py-interactions at that point – plus, we’re already a library that keeps very similar naming conventionsas discord.py does, so this is pointless.

50 Chapter 2. Where do I start?

Page 55: PAGES - Read the Docs

discord-interactions, Release 4.0.0

2.3.3 Will discord.py be able to work with this library?

The short answer is: yes.However, the term “work” is loosely structured here. Imagine it like taping a hole in the wall instead of repairing thewall. We’re essentially “plastering” support for discord.py instead of doing the surgery on its internal organs to makeit work well with our library. As it currently stands, discord-interactions and discord.py are API wrappers. You willbe able to run code alongside one another, and you will be able to plug in some classes, but the data conversion mustbe exact.What does that mean? Well, we’ll show you:

import interactionsfrom discord.ext import commands

interactions = interactions.Client(token="...")dpy = commands.Bot(prefix="/")

@dpy.command()async def hello(ctx):

await ctx.send("Hello from discord.py!")

@interactions.command(name="test",description="this is just a testing command."

)async def test(ctx):

await ctx.send("Hello from discord-interactions!")

interactions.start()dpy.run(token="...", bot=True)

Both of these variables interactions and dpy will be able to run in the same established environment, and addition-ally will both function properly as their respective libraries intend them to. What about the models, though? That’s asimple answer:

import discordfrom interactions.api.models.member import Member

@dpy.command()async def borrowing(ctx, member: Member):

await ctx.send(f"Member ID: {member.id}")

@interactions.command(...)async def second_borrowing(ctx, member: discord.Member):

await ctx.send(f"Member ID: {member.id}")

Both of these will be able to both run and give their proper value. It is very important to note here, though, that youmust be returning back the exact same information that our objects depend on. A missing class instance can easilylead to it breaking, hence the “plastering” that is going on here.

2.3. Frequently Asked Questions 51

Page 56: PAGES - Read the Docs

discord-interactions, Release 4.0.0

2.3.4 Where should we go with discord.py being gone?

The most biased answer would be to, of course, use discord-interactions. We already offer a lot of the integral APIwrapper aspects as discord.py does, however, we only specialize in interactions. Which means things such as thesewon’t be supported officially by us (but might be available as 3rd parties):

• Cooldowns

• Message commands

• Voice clients

There are other libraries of course though. As a general rule of thumb, if you’re looking to do mainly slash commandsand that tidbit then we highly recommend using our library, especially as discord-components merges as of version4.0. But if you want something way more open and versatile, then we recommend these sources:

• Pycord (the most actively maintained).

• dis-snek (high level, “hackable” API wrapper with ease of modification).

• nextcord (more abstract and fast approach to the Discord API).

It’s personally recommended from the library developer to seek these paths instead of sticking to an older version ofa library, e.g. discord.py 1.7.3 or 2.0.0a as they can eventually become deprecated with more pending changes to theAPI by Discord engineers.

2.3.5 Why are you not supporting cooldowns?

Cooldowns aren’t really an actual feature of the Discord API itself, but rather more of a convienent feature implementedin discord.py in order to avoid spamming of commands.

What if people spam slash/sub commands?That’s the neat part: it’s really hard to do that, and most of the time, they won’t. Unless they copy the exact string thatwas used when you open up the UI element to do it numerous times, most users do and will not be able to know howto do this. However, if you as a bot developer feel at unease about this, you are more than welcome to implement yourown cooldown methods yourself. Cooldowns were an ultimatum that came as the result of message commands beingable to be spammable, and since we won’t be supporting them, there’s no feasibility to having them in our library.

2.3.6 Will we not be able to create message commands?

This is a tricky question to really answer. If you want the technical answer: you can definitely create them with ourlibrary, however, you’ll have to program them in the on_message_create listener event that we use. This is alreadysomething a majority of discord.py bot developers frown upon doing, so this is at your own risk to code your owncommand handlers into it. Luckily, you can take a page out of discord.js’ book if you want to do this, since they’venever heard of an external command handler framework before in their entire life.

52 Chapter 2. Where do I start?

Page 57: PAGES - Read the Docs

discord-interactions, Release 4.0.0

2.3.7 My question is not answered on here!

Please join our Discord server for any further support regarding our library and/or any integration code depending onit.

• Invite Link: https://discord.gg/KkgMBVuEkx

2.3. Frequently Asked Questions 53

Page 58: PAGES - Read the Docs

discord-interactions, Release 4.0.0

54 Chapter 2. Where do I start?

Page 59: PAGES - Read the Docs

CHAPTER

THREE

ADVANCED SEARCH

• genindex

• modindex

• search

55