mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 01:40:08 +00:00
first request to discord api success
This commit is contained in:
22
module/Client.ts
Normal file
22
module/Client.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { endpoints } from "../constants/discord.ts"
|
||||
import RequestHandler from "../services/RequestHandler.ts"
|
||||
|
||||
class Client {
|
||||
/** The bot's token. This should never be used by end users. It is meant to be used internally to make requests to the Discord API. */
|
||||
token: string
|
||||
/** The Rate limit manager to handle all outgoing requests to discord. Not meant to be used by users. */
|
||||
RequestHandler: RequestHandler
|
||||
|
||||
constructor(token: string) {
|
||||
this.token = `Bot ${token}`
|
||||
this.RequestHandler = new RequestHandler(this, this.token)
|
||||
}
|
||||
|
||||
async connect() {
|
||||
// const data = await fetch(endpoints.GATEWAY_BOT).then(res => res.json())
|
||||
// console.log(data)
|
||||
console.log(await this.RequestHandler.get(endpoints.GATEWAY_BOT))
|
||||
}
|
||||
}
|
||||
|
||||
export default Client
|
||||
31
services/RequestHandler.ts
Normal file
31
services/RequestHandler.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import Client from "../module/Client.ts";
|
||||
|
||||
class RequestHandler {
|
||||
client: Client
|
||||
token: string
|
||||
|
||||
constructor(client: Client, token: string) {
|
||||
this.client = client
|
||||
this.token = token
|
||||
}
|
||||
|
||||
async get(url: string, payload?: unknown) {
|
||||
// THIS IS IMPORTANT. It keeps clean stack errors in the users own files to better help debug errors.
|
||||
// const stackHolder = {};
|
||||
// TODO: Figure out why this doesnt work
|
||||
// Error.captureStackTrace(stackHolder)
|
||||
|
||||
// let attempts = 0
|
||||
const headers = {
|
||||
Authorization: this.token,
|
||||
"User-Agent": `DiscordBot (https://github.com/skillz4killz/discordeno, 0.0.1)`,
|
||||
}
|
||||
|
||||
console.log('payload', payload)
|
||||
|
||||
const data = await fetch(url, { headers }).then(res => res.json())
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
export default RequestHandler
|
||||
Reference in New Issue
Block a user