Skip to content
Shell edited this page Jan 21, 2024 · 15 revisions

Introduction to the Bot instance

This instance encapsulates the functionality, configuration, and behavior of your bot, allowing you to interact with the Discord API, handle events, and define commands. It represents the selfbot. Some stuff may change at the time of writing.

I'll just be identifying attributes and methods that are most important here.

Initialisation

Bot(
    prefixes: list[str] = ["s!"],
    inbuilt_help: bool = True,
    userbot: bool = False,
    token_leader: Optional[str] = None, # for multi-token, what user-id they listen to for commands
    eval: bool = False, # Whether eval command should be added to commands
    decompress: bool = True, # Whether gateway should decompress, use `True` by default
    password: Optional[str] = None # i forgo i'm gonna remove this anyways
)

Attributes/Properties

Your token

self.token: str

Commands

self.commands: CommandCollection

The bot client, the actual user

self.user: Client

The tokens loaded from mass token stuff

self.bots: list[Bot]

The extensions loaded

self.extensions: ExtensionCollection

The bots session id

self.session_id: str

The bots resume_url for gateway

self.resume_url: str

Methods

Used to start the gateway event loop. Self explanatory 😭.

def run(self, token: str)

Command decorator, used to create commands for the bot. The mass_token when set to True, will append the command only for the mass-token instances. See multi-token for more information on how it works.

def cmd(self, description="", aliases=[], mass_token: bool = False)

Example Usage

@bot.command(description="Purges messages", aliases=["clear"])
async def purge(ctx, n: int):
  await ctx.purge(n)

Event decorator, used to create events for the bot. The mass_token when set to True, will append the event only for the mass-token instances. See multi-token for more information on how it works.

def on(self, event: str, mass_token: bool = False)

The event names are going to be the same as their official event names in the API (other than message_create, which is just "message"). I mean I guess you can ask but most of them are here listed in discords own docs. There are some specific user only events, I'm just too lazy to write them all right now. Remember to use snake_case when specifying events in the decorator.

Example Usage

@bot.on("message_delete")
async def msg_logger(msg):
  print(msg.content)

Used to load tokens for mass token purposes. Read multi-token section for a better understanding on how it works.

async def load_tokens(self, tokens: list, prefixes: list[str] = ["!"], eval: bool = False)

Used to load extensions for modularity/code organisation purposes. Read extensions section for a better understanding on how it works.

async def load_extension(self, name: str | None = None, url: str | None = None, dir: str | None = None)
Clone this wiki locally