diff --git a/README.md b/README.md index 18c322d..7e6f1a2 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ from miniscord import Bot import discord + async def hello(client: discord.client, message: discord.Message): await message.channel.send("Hello!") @@ -22,12 +23,12 @@ bot.register_command( "hello", # command text (regex) hello, # command function "hello: says 'Hello!'", # short help - f"```\n" # long help - f"* |help\n" - f"\tSays 'Hello!'.\n" - f"```" + "```\n" # long help + "* |help\n" + "\tSays 'Hello!'.\n" + "```" ) -bot.start() # this bot respond to "|help", "|info" and "|hello" +bot.start() # this bot respond to "|help", "|info" and "|hello" ``` ![](./sample.jpg) @@ -275,9 +276,10 @@ async def hello(client: discord.client, message: discord.Message, *args: str): ''' if len(args) > 1: await message.channel.send(f"Hello {args[1]}!") - else : + else: await message.channel.send("Hello stranger!") + async def mention(client: discord.client, message: discord.Message, *args: str): channels[channel_id(message)] += 1 senders[sender_id(message)] += 1 @@ -286,6 +288,7 @@ async def mention(client: discord.client, message: discord.Message, *args: str): f"{channels[channel_id(message)]} mentions on this channel so far" ) + async def message(client: discord.client, message: discord.Message): if "catapult" in message.content: sent_msg = await message.channel.send(f"{message.author.mention} No profanity on this server") @@ -304,10 +307,10 @@ bot.register_command( "hello", # command text (regex) hello, # command function "hello: says 'Hello!'", # short help - f"```\n" # long help - f"* |help\n" - f"\tSays 'Hello!'.\n" - f"```" + "```\n" # long help + "* |help\n" + "\tSays 'Hello!'.\n" + "```" ) bot.register_fallback(mention) # the bot was mentioned or the alias was used diff --git a/miniscord/_bot.py b/miniscord/_bot.py index 55949c0..ccf5b84 100644 --- a/miniscord/_bot.py +++ b/miniscord/_bot.py @@ -8,7 +8,7 @@ import asyncio import random import os from datetime import datetime -from dotenv import load_dotenv +from dotenv import load_dotenv, find_dotenv from ._utils import sanitize_input, parse_arguments @@ -105,10 +105,10 @@ class Bot(object): if len(args) <= 1: tmp_alias = '' if self.alias is None else self.alias await message.channel.send( - f"```\n" - f"List of available commands:\n" + - "".join([f"* {tmp_alias}{command.help_short}\n" for command in self.__commands]) + - f"```" + "```\n" + "List of available commands:\n" + + "".join([f"* {tmp_alias}{command.help_short}\n" for command in self.__commands]) + + "```" ) else: for command in self.__commands: @@ -210,7 +210,7 @@ class Bot(object): def start(self): logging.info(f"Current PID: {os.getpid()}") - env_file_found = load_dotenv() + env_file_found = load_dotenv(find_dotenv()) self.__token = os.getenv(self.token_env_var) if self.__token is None: if env_file_found: