R_Milligan3

os module error

Jan 29th, 2022 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import os
  2. import discord
  3. from discord.ext import commands
  4. from fastapi import FastAPI
  5. import asyncio
  6. from pydantic import BaseModel
  7.  
  8.  
  9. token = 'Discord Bot Token'
  10. app=FastAPI()
  11. client = commands.Bot(command_prefix='!')
  12.  
  13. class Item(BaseModel):
  14. name:str
  15. price:float
  16. brand:str
  17.  
  18. @app.get('/')
  19. async def hello():
  20. return {'Hello':'You'}
  21.  
  22. client.event
  23. async def on_ready():
  24. print(f"Logged in as {client.user} Running with FastAPI")
  25.  
  26. @client.command()
  27. async def welcome(ctx:commands.Context,member:discord.Member):
  28. await ctx.send(f"Welcome to {ctx.guild.name}")
  29.  
  30. async def run():
  31. try:
  32. await client.start(token)
  33. except KeyboardInterrupt:
  34. await client.logout()
  35.  
  36. @app.put('/item/{item_id}')
  37. async def get_item(item_id:int,item:Item):
  38. result={'item_id':item_id,'item':item}
  39. return result
  40.  
  41. @client.command()
  42. async def load(ctx,extension):
  43. client.load_extension(f"Cogs.{extension}")
  44. #asyncio.create_task(run())
  45.  
  46. @client.command()
  47. async def unload(ctx,extension):
  48. client.unload_extension(f"Cogs.{extension}")
  49.  
  50. for filename in os.listdir('./Cogs'):
  51. if filename.endswith('.py'):
  52. client.load_extension(f'Cogs.{filename[:-3]}')
  53.  
  54. client.run(token)
  55.  
  56.  
Add Comment
Please, Sign In to add comment