diff options
| author | 2022-03-24 13:26:21 +0400 | |
|---|---|---|
| committer | 2022-03-24 13:26:21 +0400 | |
| commit | caaecf572615e9177fe53c6f81212d7a7ca6d2f6 (patch) | |
| tree | d67816bd0850ed75ad09ffd6db0639307e11f386 | |
| parent | Add single space after quotes (diff) | |
Update subclassing_bot.md
| -rw-r--r-- | pydis_site/apps/content/resources/guides/python-guides/subclassing_bot.md | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/pydis_site/apps/content/resources/guides/python-guides/subclassing_bot.md b/pydis_site/apps/content/resources/guides/python-guides/subclassing_bot.md index 5f1e7ccf..0f9dbf78 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/subclassing_bot.md +++ b/pydis_site/apps/content/resources/guides/python-guides/subclassing_bot.md @@ -14,31 +14,40 @@ There are two ways to subclass `commands.Bot`, as shown below: class CustomBot(commands.Bot): def __init__(self): super().__init__( - command_prefix = # your prefix here as a string - intents = # your intents here - # other kwargs can be put here + command_prefix = #your prefix here as a string + intents = #your intents here + #other kwargs can be put here ) - # custom bot attributes can be set here, for example: - self.db = self.loop.run_until_complete(aiosqlite.connect("Your database file name")) + #custom bot attributes can be set here, for example: self.launch_time = datetime.datetime.utcnow() self.example_integer = 5 + + async def start(self, *args, **kwargs): + # here you are overriding the default start method. You can do some code here for example establish a database connection + #as shown in this example below + self.db = await aiosqlite.connect('database file name.db') + await super().start(*args, **kwargs) + + bot = CustomBot() +token = YOUR_TOKEN_HERE +bot.run(token) ``` Or ```py class CustomBot(commands.Bot): - def __init__(self, *args, **kwargs): # the key-word arguments are not specified here, unlike the example above + def __init__(self, *args, **kwargs): #the key-word arguments are not specified here, unlike the example above super().__init__(*args, **kwargs) - # custom bot attributes can be set here, for example: + #custom bot attributes can be set here, for example: self.example_string = 'This is an example!' - # You can add a custom bot method, anything can be done in this function. This is an example: + #You can add a custom bot method, anyhting can be done in this function. This is an example: def hello(self): return 'Hello World' -# Here you set the *args and **kwargs +#Here you set the *args and **kwargs bot = CustomBot(command_prefix="!", intents=discord.Intents.default()) @bot.command() |