# Basic usage

### Create a bot.py file

This file define your bot.

{% code title="bot.py" %}

```python
import asyncio
import discord
from baseDiscord import BaseBot


class MyBot(BaseBot):
    def __init__(self, *args, **kwargs)
        super().__init__(*args, **kwargs)
    
    async def on_connect(self):
        self.logger("My bot is connected!")
        await super().on_connect()
    
    async def on_disconnect(self):
        self.logger("My bot is disconnected")
        await super().on_disconnect()
```

{% endcode %}

{% hint style="info" %}
You can overwrite events of [`discord.ext.commands.Bot`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#bots).&#x20;
{% endhint %}

### Create cogs

Create a folder "cogs". In this folder you can create all cogs than you want.

{% code title="./cogs/hello.py" %}

```python
import asyncio
import discord
from discord.ext import commands
from discord_slash import cog_ext


class Hello(commands.Cog):
    def __init__(self, bot):
        super().__init__()
        self.bot = bot
    
    @cog_ext.slash(name="hello", description="Say hello")
    async def hello(self, ctx):
        await ctx.send(f"Hello {ctx.author.mention}!")
```

{% endcode %}

{% hint style="info" %}
Look the documentation of [discord\_slash](https://discord-py-slash-command.readthedocs.io/en/latest/) for more information on slash commands
{% endhint %}

## Create a main.py file

This file is the main script to execute. The bot is created in this file.

{% code title="main.py" %}

```python
import discord
from discord_slash import SlashCommand
from baseDiscord import Help, Owner

from cogs import hello
from bot import MyBot


# Parameters
TOKEN = "my token"
PREFIX = "!"
COLOR = discord.Color.blue()

# Init
client = MyBot(token=TOKEN, prefix=PREFIX, color=COLOR, intents=discord.Intents.all())
slash = SlashCommand(client, sync_commands=True)

# Add cogs
Help.setup(client)
Owner.setup(client)
hello.Hello.setup(client)

# run the bot
bot.run()
```

{% endcode %}

{% hint style="success" %}
You are created a minimalist bot ! :smiley:&#x20;
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lostpy.gitbook.io/basediscord-py/usage/basic-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
