Advertisement
Guest User

Untitled

a guest
May 14th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import discord
  2. from discord.ext.commands import Bot
  3. from sqlalchemy import create_engine
  4. from sqlalchemy.ext.asyncio import AsyncSession
  5. from sqlalchemy.orm import sessionmaker
  6. from sqlalchemy_utils import database_exists, create_database
  7.  
  8. from models import User
  9. from settings import TOKEN_TEST, DATABASE_URL, DB_ECHO
  10.  
  11. intents = discord.Intents().all()
  12. bot = Bot(command_prefix='!', intents=intents)
  13.  
  14. engine = create_engine(DATABASE_URL, echo=DB_ECHO, )
  15. # Session = sessionmaker(bind=engine)
  16. async_session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
  17. # session = Session()
  18.  
  19. if not database_exists(engine.url):
  20.     create_database(engine.url)
  21.  
  22. print(engine.name)
  23. print(engine.url)
  24.  
  25.  
  26. @bot.event  # Статус у бота
  27. async def on_ready():
  28.     if not await database_exists(engine.url):
  29.         create_database(engine.url)
  30.     print('bot is online!')
  31.  
  32.  
  33.  
  34. @bot.event
  35. async def on_guild_join(guild):
  36.     print(guild)
  37.  
  38.  
  39. @bot.command()
  40. async def test(ctx):
  41.     z = bot.guilds
  42.     ed_user = User(name='ed', fullname='Ed Jones', nickname='edsnickname')
  43.  
  44.     await ctx.send(f'Work it! {z}')
  45.  
  46.  
  47. if __name__ == '__main__':
  48.     try:
  49.         bot.run(TOKEN_TEST)
  50.     except Exception as e:
  51.         print('Could Not Start Bot')
  52.         print(e)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement