扩展客户端缺少的功能

Extended Client missing functions

我目前正在工作,将我的 discord 机器人从 js 重写为 ts。 为了使用打字,我扩展了 discord.js 客户端,我无法获取频道并在那里发送消息。除了使用 type:any?

之外,我该如何解决这个问题

我的扩展客户端:

export class DiscordClient extends Client {
    commands
    config
}

这不再适用于 Client 类型设置为 DiscordClient。 如果我将它设置为任何,它工作正常

client.channels.cache
        .find((channel) => channel.id == client.config.ids.channelIDs.dev.botTestLobby)
        .send({ embeds: [loginMessage] })

可以有多种类型的渠道(文本、语音等),TypeScript 不知道您.find正在使用哪种类型的渠道,而且并非每种渠道类型都有 .send功能(语音频道不能发消息)

要解决此问题,如果您确定存储在 client.config 中的频道 ID 是文本频道 ID,则可以使用 type assertion 将该变量的类型更改为 TextChannel.

这是它的样子:

const channel = client.channels.cache.find((channel) => channel.id == client.config.ids.channelIDs.dev.botTestLobby) as TextChannel
channel.send({ embeds: [loginMessage] })