示例#1
0
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.

import logging

from discord import Intents
from discord.ext.commands.bot import Bot, when_mentioned

from os import environ

if __name__ == '__main__':
    logging.basicConfig(format='[%(levelname)s] %(name)s: %(message)s', level=logging.INFO)
    
    opts = Intents(messages=True, guilds=True)
    bot = Bot(when_mentioned, case_insensitive=True, intents=opts)
    bot.logger = logging.getLogger()

    bot.load_extension('cogs')

    try:
        bot.run(environ['DISCORD_TOKEN'])
    except KeyError:
        print('Token for accessing Discord API was not given')
示例#2
0
from discord.ext.commands.bot import Bot
from discord import Message, TextChannel, Webhook, AsyncWebhookAdapter
from os import getenv
import aiohttp

bot = Bot("m!")

quote_wall_id = 692999924349927514
webhook_url = getenv("WEBHOOK_URL")
bot_token = getenv("BOT_TOKEN")


@bot.event
async def on_ready():
    print("I'm awake now")


@bot.event
async def on_message(message: Message):
    async with aiohttp.ClientSession() as session:
        target_webhook = Webhook.from_url(webhook_url,
                                          adapter=AsyncWebhookAdapter(session))
        if message.channel.id == quote_wall_id:
            await target_webhook.send(
                message.content,
                username=message.author.display_name,
                avatar_url=message.author.avatar_url,
                files=[
                    await file.to_file(spoiler=file.is_spoiler())
                    for file in message.attachments
                ])
示例#3
0
from discord.ext.commands.bot import Bot
from discord import Intents
import Code.Cogs.Base as Base
from Code.Cogs.ModToolsCogs import UserWarnCog, AutoDrawingPrompt
from Code.Cogs.MessagingCogs import HelpCog, TagCog, CookieHuntCog, DiceRollerCog
from Code.Cogs.SystemInteractionCogs import GlobalErrorHandlingCog, RoleRequestCog, AirlockCog

if __name__ == '__main__':
    # Build the bot
    Base.ConfiguredCog.logger.info('Constructing Manageable bot...')
    Base.ConfiguredCog.logger.debug(f'Building bot.')

    intents = Intents.default()
    intents.members = True  # Among others, the help command needs the members intent to monitor reactions

    discord_bot = Bot(Base.ConfiguredCog.config['command_prefix'],
                      intents=intents)

    Base.ConfiguredCog.logger.debug('Removing built-in help command.')
    discord_bot.remove_command('help')  # We are providing our own help command

    # Add the necessary cogs
    Base.ConfiguredCog.logger.info('Attaching functionality...')

    # Do not disable
    Base.ConfiguredCog.logger.debug('Adding GlobalErrorHandling Cog.')
    discord_bot.add_cog(GlobalErrorHandlingCog(discord_bot))

    # Do not disable
    Base.ConfiguredCog.logger.debug('Adding Help Cog.')
    discord_bot.add_cog(HelpCog(discord_bot))
示例#4
0
from logging.config import dictConfig
from logging import getLogger, Formatter, FileHandler, StreamHandler, info, critical, INFO
from os import environ
from sys import stdout
from traceback import print_tb
from json import load

from discord import Color
from discord.ext.commands import errors
from discord.ext.commands.bot import Bot
from pymongo import MongoClient
from motor.motor_asyncio import AsyncIOMotorClient

from utils.embed import create_embed

BOT = Bot(command_prefix="$", pm_help=False)  # Create the bot
BOT.mongo = AsyncIOMotorClient(host=environ["MONGO_HOST"], port=int(environ["MONGO_PORT"]),
                               connect=True)

# Extensions to load at start
LOGGER = getLogger("discord_against_humanity.bot")
EXTENSIONS = ["commands.discord_against_humanity"]


def init_logger():
    """Set the logger to the desired level

    Keyword Arguments:
        level {int} -- Level of logging (default: {INFO})
    """
    with open("logging.json", "r") as config_file: