Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext.commands import Bot
- from sqlalchemy import create_engine
- from sqlalchemy.ext.asyncio import AsyncSession
- from sqlalchemy.orm import sessionmaker
- from sqlalchemy_utils import database_exists, create_database
- from models import User
- from settings import TOKEN_TEST, DATABASE_URL, DB_ECHO
- intents = discord.Intents().all()
- bot = Bot(command_prefix='!', intents=intents)
- engine = create_engine(DATABASE_URL, echo=DB_ECHO, )
- # Session = sessionmaker(bind=engine)
- async_session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
- # session = Session()
- if not database_exists(engine.url):
- create_database(engine.url)
- print(engine.name)
- print(engine.url)
- @bot.event # Статус у бота
- async def on_ready():
- if not await database_exists(engine.url):
- create_database(engine.url)
- print('bot is online!')
- @bot.event
- async def on_guild_join(guild):
- print(guild)
- @bot.command()
- async def test(ctx):
- z = bot.guilds
- ed_user = User(name='ed', fullname='Ed Jones', nickname='edsnickname')
- await ctx.send(f'Work it! {z}')
- if __name__ == '__main__':
- try:
- bot.run(TOKEN_TEST)
- except Exception as e:
- print('Could Not Start Bot')
- print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement