From afa46c4abfc73c8791742ed2ece886776823e8ab Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Sat, 23 Jul 2022 14:47:06 +0200 Subject: Add Sample Project With Boilerplate Adds a bare-bones discord.py bot using features from bot-core, to be used for quickly prototyping and testing out bot-core features. Signed-off-by: Hassan Abouelela --- dev/bot/__main__.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 dev/bot/__main__.py (limited to 'dev/bot/__main__.py') diff --git a/dev/bot/__main__.py b/dev/bot/__main__.py new file mode 100644 index 00000000..00ebdefc --- /dev/null +++ b/dev/bot/__main__.py @@ -0,0 +1,34 @@ +import asyncio +import os + +import aiohttp +import discord +import dotenv +from discord.ext import commands + +import botcore +from . import Bot + +dotenv.load_dotenv() +botcore.utils.apply_monkey_patches() + +roles = os.getenv("ALLOWED_ROLES") +roles = [int(role) for role in roles.split(",")] if roles else [] + +bot = Bot( + guild_id=int(os.getenv("GUILD_ID")), + http_session=None, # type: ignore # We need to instantiate the session in an async context + allowed_roles=roles, + command_prefix=commands.when_mentioned_or(os.getenv("PREFIX", "!")), + intents=discord.Intents.all(), + description="Bot-core test bot.", +) + + +async def main() -> None: + """Run the bot.""" + bot.http_session = aiohttp.ClientSession() + async with bot: + await bot.start(os.getenv("TOKEN")) + +asyncio.run(main()) -- cgit v1.2.3 From ce894c0706d64756cdcd046f5729958425a803fc Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 10 Sep 2022 20:45:54 +0100 Subject: Use BOT_TOKEN in example project This is so that we use the same env var as metricity, remove the need for duplicate env vars. --- dev/README.rst | 2 +- dev/bot/__main__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/bot/__main__.py') diff --git a/dev/README.rst b/dev/README.rst index afff6255..ae4f3adc 100644 --- a/dev/README.rst +++ b/dev/README.rst @@ -40,7 +40,7 @@ Option 2 3. Configure the environment variables used by the program. You can set them in an ``.env`` file in the project root directory. The variables are: - - ``TOKEN`` (required): Discord bot token, with all intents enabled + - ``BOT_TOKEN`` (required): Discord bot token, with all intents enabled - ``GUILD_ID`` (required): The guild the bot should monitor - ``PREFIX``: The prefix to use for invoking bot commands. Defaults to mentions and ``!`` - ``ALLOWED_ROLES``: A comma seperated list of role IDs which the bot is allowed to mention diff --git a/dev/bot/__main__.py b/dev/bot/__main__.py index 00ebdefc..42d212c2 100644 --- a/dev/bot/__main__.py +++ b/dev/bot/__main__.py @@ -29,6 +29,6 @@ async def main() -> None: """Run the bot.""" bot.http_session = aiohttp.ClientSession() async with bot: - await bot.start(os.getenv("TOKEN")) + await bot.start(os.getenv("BOT_TOKEN")) asyncio.run(main()) -- cgit v1.2.3