Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Client

The base Client to access and configure your discord bot. The client should be imported from fuwa.js and extended either as a variable or class.

example
import { Client } from "fuwa.js"
const bot = new Client({})
// or
class bot extends Client {}

Both will work in javascript or typescript.

Hierarchy

  • WebSocket
    • Client

Index

Constructors

constructor

Properties

_interactionListeners

_interactionListeners: Map<string, CommandCallback> = ...

Interaction listeners for buttons

applicationId

applicationId: string

Your bot ID

bot

bot: BotUser = null

cache

cache: Cache

commands

commands: Map<string, Command> = ...

A Map of commands

Protected connected

connected: boolean = false

Protected debug

debug: Debug

events

events: Map<keyof EventHandlersDefinitions, (...args: any[]) => any> = ...

A Map of fuwa#client events

Protected intents

intents: ("Guilds" | "GuildMembers" | "GuildBans" | "GuildEmojis" | "GuildIntegrations" | "GuildWebhooks" | "GuildInvites" | "GuildVoiceStates" | "GuildPresences" | "GuildMessages" | "GuildMessageReactions" | "GuildMessageTyping" | "DirectMessages" | "DirectMessageReactions" | "DirectMessageTyping")[]

DiscordAPI GateWay Intents

Protected Optional loop

loop?: Timeout

mountingCommands

mountingCommands: Command[] = ...

Commands that will be mounted before the ready event

once

once: <T>(event: T, callback: EventHandlers[T]) => Client = ...

Type declaration

    • <T>(event: T, callback: EventHandlers[T]): Client
    • Alias for on

      Type parameters

      • T: keyof EventHandlersDefinitions

        The event name

      Parameters

      • event: T
      • callback: EventHandlers[T]

      Returns Client

Protected options

options: ClientOptions

Options to pass to the client

plugins

plugins: Plugin[]

Protected response

response: { events: { emit: <T>(t: T, d: GatewayEvents[T]) => void }; op: { emit: <T>(op: T, d: GatewayCommands[T]["d"]) => void } } = ...

Type declaration

  • events: { emit: <T>(t: T, d: GatewayEvents[T]) => void }
    • emit: <T>(t: T, d: GatewayEvents[T]) => void
        • <T>(t: T, d: GatewayEvents[T]): void
        • Type parameters

          • T: keyof GatewayEvents

          Parameters

          • t: T
          • d: GatewayEvents[T]

          Returns void

  • op: { emit: <T>(op: T, d: GatewayCommands[T]["d"]) => void }
    • emit: <T>(op: T, d: GatewayCommands[T]["d"]) => void
        • <T>(op: T, d: GatewayCommands[T]["d"]): void
        • Type parameters

          • T: number

          Parameters

          • op: T
          • d: GatewayCommands[T]["d"]

          Returns void

Protected session

session: { id: string; seq: number } = ...

Type declaration

  • id: string
  • seq: number

shardCount

shardCount: number

Protected token

token: string = ''

ws

ws: any

Methods

command

  • command(name: string, data: CommandCallback | { args?: Argument[]; desc?: string; guild?: string }, cb?: CommandCallback): Client

Protected connect

  • connect(url: string, version: 6 | 8 | 9): void
  • ws connection

    Parameters

    • url: string

      websocket url to connect to

    • version: 6 | 8 | 9

      api version to connect to

    Returns void

Protected event

  • event<T>(e: T, cb: (data: GatewayEvents[T]["d"]) => void): void
  • Type parameters

    • T: keyof GatewayEvents

    Parameters

    • e: T
    • cb: (data: GatewayEvents[T]["d"]) => void
        • (data: GatewayEvents[T]["d"]): void
        • Parameters

          • data: GatewayEvents[T]["d"]

          Returns void

    Returns void

getChannel

  • getChannel(cid: string, force?: boolean): Promise<Channel>

getGuild

  • getGuild(gid: string, withSize?: boolean, force?: boolean): Promise<Guild>
  • Allows easy access to the fuwa.js#Guild information.

    Parameters

    • gid: string

      Id of the guild you want to fetch

    • withSize: boolean = false

      If you want the guild to contain the approximant member count of the guild (and presences), warning this may slow down the request so only use if needed

    • force: boolean = false

    Returns Promise<Guild>

    A Guild, or null if the guild was not found

getMountedCommands

  • getMountedCommands(guildId?: string): Promise<ApplicationCommand[]>
  • Returns all mounted commands and there discord data.

    Parameters

    • Optional guildId: string

      the id of the guild your application command is registered in.

    Returns Promise<ApplicationCommand[]>

getUser

  • getUser<T>(uid: T): Promise<T extends "@me" ? BotUser : User>

login

  • login(token?: string | Buffer): void

logout

  • logout<T>(end: T): T extends true ? void : never

mountCommand

on

  • on<T>(event: T, callback: EventHandlers[T]): Client

Protected op

  • op<T>(op: T, cb: (data: GatewayCommands[T]["d"]) => void): void
  • Type parameters

    • T: number

    Parameters

    • op: T
    • cb: (data: GatewayCommands[T]["d"]) => void
        • (data: GatewayCommands[T]["d"]): void
        • Parameters

          • data: GatewayCommands[T]["d"]

          Returns void

    Returns void

Protected parseDiscordEventNames

  • parseDiscordEventNames(e: string): string

Protected spawnShard

  • spawnShard(shardId: number, data: Identify): Promise<void>

unmountCommand

  • unmountCommand(cmd: string | Command, guildId?: string): Promise<{ _metadata: any; blob: Blob; buffer: Buffer; data: any; headers: Map<string, string>; status: HTTPResponseCodes }>
  • Deletes a command from the discord api.

    Parameters

    • cmd: string | Command

      command id

    • Optional guildId: string

      only needed if your command is a guild command and your id is a string

    Returns Promise<{ _metadata: any; blob: Blob; buffer: Buffer; data: any; headers: Map<string, string>; status: HTTPResponseCodes }>

Protected wsEvent

  • wsEvent<T>(e: T, cb: (data: any) => any): void
  • Type parameters

    • T: "message" | "open"

    Parameters

    • e: T
    • cb: (data: any) => any
        • (data: any): any
        • Parameters

          • data: any

          Returns any

    Returns void