Skip to content

Multi Token

Shell edited this page Jan 17, 2024 · 1 revision

Control multiple bots with selfcord

These methods and and attributes are all part of the Bot class.

Loading and using tokens

This method loads tokens into the bot, the loaded tokens will be under self.bots and self.tokens attributes.

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

A Client object per token is stored here.

self.tokens: list[Client]

A Bot object per token is stored here.

self.bots: list[Bot]

Use these methods to edit the token if needed, access their cache, use specific methods, etc.

Example Usage

This example serves as a foundation for managing multiple bots using selfcord, enabling you to extend the functionality across different bot instances with distinct configurations.

# Import the library
import selfcord

# Set your bot token
token = "your token"

# Create a bot instance with specified configurations
bot = selfcord.Bot(
    prefixes=["!", "?"],  # We allow multiple prefixes
    eval=True,            # There are some inbuilt commands by default
    inbuilt_help=False
)

# Define an event handler for the "ready" event
@bot.on("ready")
async def ready(time):
    print(f"Bot was ready in {time:.2f} seconds")
    await bot.load_tokens([
        "token-2",
        "token-3"
    ], prefixes=[">"], eval=True) # They also can have different prefixes


@bot.cmd(description="Spam 5 messages", mass_bot=True) # Initialise this command for mass token only
async def spam(ctx):
    for i in range(5):
        await ctx.send("poopoo") # All the tokens will send 5 messages

@bot.on("message", mass_bot=True) # Initialise this event for mass token only
async def sniper(msg):
    print(msg.content)


# Run the bot with the specified token
bot.run(token)
Clone this wiki locally