fix: more bugs in client pkg

This commit is contained in:
Skillz
2023-02-28 18:50:46 -06:00
parent 4c8b658093
commit dd699768eb
2 changed files with 50 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ import {
type GetMessagesOptions,
type OverwriteTypes,
} from '@discordeno/types'
import { delay, getBotIdFromToken, iconBigintToHash, iconHashToBigInt } from '@discordeno/utils'
import { delay, getBotIdFromToken, iconBigintToHash, iconHashToBigInt, snakelize } from '@discordeno/utils'
import EventEmitter from 'node:events'
import Base from './Base.js'
import Collection from './Collection.js'
@@ -163,6 +163,7 @@ import type {
BotActivityType,
ChannelFollow,
ChannelPosition,
ClientEvents,
CreateChannelInviteOptions,
CreateChannelOptions,
CreateGuildOptions,
@@ -383,6 +384,11 @@ export class Client extends EventEmitter {
return this._privateChannelMap.toRecord()
}
on<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this
on(event: string, listener: (...args: any[]) => void): this {
return super.on(event, listener)
}
/** Tells all shards to connect. This will call `getBotGateway()`, which is ratelimited. */
async connect(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
@@ -435,7 +441,7 @@ export class Client extends EventEmitter {
/** Make a GET request to the discord api. */
async get(url: string): Promise<any> {
return await this.requestHandler.discordeno.get(url)
return snakelize(await this.requestHandler.discordeno.get(url))
}
/** Make a POST request to the discord api. */
@@ -447,7 +453,13 @@ export class Client extends EventEmitter {
file?: FileContent | FileContent[]
},
): Promise<any> {
return await this.requestHandler.discordeno.post(url, payload)
return snakelize(
await this.requestHandler.discordeno.post(url, {
reason: payload?.reason,
file: payload?.file,
...payload?.body,
}),
)
}
/** Make a PATCH request to the discord api. */
@@ -459,7 +471,19 @@ export class Client extends EventEmitter {
file?: FileContent | FileContent[]
},
): Promise<any> {
return await this.requestHandler.discordeno.patch(url, payload)
return snakelize(
await this.requestHandler.discordeno.patch(
url,
payload?.file ?? payload?.reason
? {
reason: payload.reason,
file: payload.file,
// @ts-expect-error js hacks plz stop
...payload.body,
}
: payload?.body,
),
)
}
/** Make a PUT request to the discord api. */
@@ -470,7 +494,17 @@ export class Client extends EventEmitter {
reason?: string
},
): Promise<any> {
return await this.requestHandler.discordeno.put(url, payload)
return snakelize(
await this.requestHandler.discordeno.put(
url,
Array.isArray(payload?.body)
? payload!.body
: {
reason: payload?.reason,
...payload?.body,
},
),
)
}
/** Make a DELETE request to the discord api. */

View File

@@ -36,5 +36,15 @@ We are going to use [NayuBot](https://github.com/AwesomeStickz/Nayu-Bot) which i
At this moment in time, the tsc terminal(from now on we are going to refer to this as TypeScript), is telling us we have 13 errors. This is because when we removed eris, we also need to fix any imports it may have. So let's run a search in VSC to find any `from 'eris';` and `from "eris"`. We need to replace these with `from '@discordeno/client'` and `from "@discordeno/client"`.
Tada! Time to run!
## Intents
Eris was still using an older version of the api. This meant, that intents like MessageContent was not yet supported. When switching to Discordeno, we use the latest API version possible to provide the best experience possible. This requires that if your bot needs the `MessageContent` intent, that it provide it in the intents.
```ts
// If you provide intents like this, make sure to update the number with MessageContent intent.
intents: 4086,
// If you provide intents like this, make sure to update the number with MessageContent as below
intents: ["guilds", "guildMessages", Intents.MessageContent],
```