Skip to content

Commit c187f93

Browse files
authored
Add connect.py for API connection command
1 parent e208b4b commit c187f93

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

command/dev/connect.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import discord
2+
from discord.ext import commands
3+
import aiohttp
4+
5+
import squarecloud as square
6+
from dotenv import load_dotenv
7+
import os
8+
9+
load_dotenv()
10+
11+
OWNER_ID = os.getenv("OWNER_ID")
12+
13+
intents = discord.Intents.default()
14+
intents.members = True
15+
16+
bot = commands.Bot(command_prefix='+', intents=intents)
17+
18+
@bot.tree.command(name="conectar_api", description="[Dev] Fazer uma requisição para a url da API")
19+
async def conectar_api(interaction: discord.Interaction):
20+
if str(interaction.user.id) != OWNER_ID:
21+
await interaction.response.send_message("Você não tem permissão para fazer isso!", ephemeral=True)
22+
23+
if str(interaction.user.id) == OWNER_ID:
24+
url = "https://tealand.squareweb.app/endpoint/connect"
25+
async with aiohttp.ClientSession() as session:
26+
async with session.get(url) as response:
27+
if response.status == 200:
28+
dados = await response.json()
29+
await interaction.response.send_message("Conectado com sucesso com a TeaLand!")
30+
else:
31+
await interaction.response.send_message("Não foi possível se conectar a API!", ephemeral=True)

0 commit comments

Comments
 (0)