Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import discord
- from discord.ext import commands
- from fastapi import FastAPI
- import asyncio
- from pydantic import BaseModel
- token = 'Discord Bot Token'
- app=FastAPI()
- client = commands.Bot(command_prefix='!')
- class Item(BaseModel):
- name:str
- price:float
- brand:str
- @app.get('/')
- async def hello():
- return {'Hello':'You'}
- client.event
- async def on_ready():
- print(f"Logged in as {client.user} Running with FastAPI")
- @client.command()
- async def welcome(ctx:commands.Context,member:discord.Member):
- await ctx.send(f"Welcome to {ctx.guild.name}")
- async def run():
- try:
- await client.start(token)
- except KeyboardInterrupt:
- await client.logout()
- @app.put('/item/{item_id}')
- async def get_item(item_id:int,item:Item):
- result={'item_id':item_id,'item':item}
- return result
- @client.command()
- async def load(ctx,extension):
- client.load_extension(f"Cogs.{extension}")
- #asyncio.create_task(run())
- @client.command()
- async def unload(ctx,extension):
- client.unload_extension(f"Cogs.{extension}")
- for filename in os.listdir('./Cogs'):
- if filename.endswith('.py'):
- client.load_extension(f'Cogs.{filename[:-3]}')
- client.run(token)
Add Comment
Please, Sign In to add comment