net-tech-
net-tech-
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by net-tech- on 7/28/2023 in #djs-questions
Migrating to v14 (Typescript)
Hi there I'm having trouble porting this v13 code over to v14
1 const msg = interaction.targetMessage as Message;
2
3 const components = msg?.components;
4
5 let row = components.find(
6 (x) => x.components.length < 5
7 );
8
9 if (!row) {
10 components.push(new MessageActionRow());
11 row = components[components.length - 1];
12 }
13
14 row.addComponents(button);
1 const msg = interaction.targetMessage as Message;
2
3 const components = msg?.components;
4
5 let row = components.find(
6 (x) => x.components.length < 5
7 );
8
9 if (!row) {
10 components.push(new MessageActionRow());
11 row = components[components.length - 1];
12 }
13
14 row.addComponents(button);
More specifically, in v14, ActionRow is private and components won't accept ActionRowBuilder because
Type 'ActionRowBuilder<AnyComponentBuilder>' is missing the following properties from type 'ActionRow<MessageActionRowComponent>': type, equals
Type 'ActionRowBuilder<AnyComponentBuilder>' is missing the following properties from type 'ActionRow<MessageActionRowComponent>': type, equals
.
5 replies
DIAdiscord.js - Imagine an app
Created by net-tech- on 8/18/2022 in #djs-questions
[TS] Command not found when trying to deploy commands after switching filter from .js to .ts
I have the deploy commands file from the guide in /src/util/deploy-commands.ts: https://hst.sh/ugubalayir.js running this works fine, however, when I change
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js"))
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js"))
to
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".ts"))
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".ts"))
I get the error that my ping command isn't found: https://hst.sh/yulitipaqe.js DJS v14.2.0 NODE v16.10.0
18 replies
DIAdiscord.js - Imagine an app
Created by net-tech- on 8/18/2022 in #djs-questions
Property 'commands' does not exist even after module augmentation
TypeScript DJS V14 Hi there, I'm doing
client.commands = new Collection()

const commandsPath = path.join(__dirname, "commands")
// eslint-disable-next-line security/detect-non-literal-fs-filename
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".ts"))

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
// eslint-disable-next-line @typescript-eslint/no-var-requires, security/detect-non-literal-require
const command = require(filePath)
client.commands.set(command.data.name, command)
}
client.commands = new Collection()

const commandsPath = path.join(__dirname, "commands")
// eslint-disable-next-line security/detect-non-literal-fs-filename
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".ts"))

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
// eslint-disable-next-line @typescript-eslint/no-var-requires, security/detect-non-literal-require
const command = require(filePath)
client.commands.set(command.data.name, command)
}
in my index.ts and I have
import { Collection } from "discord.js"

declare module "discord.js" {
export interface Client {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
commands: Collection<unknown, any>
}
}
import { Collection } from "discord.js"

declare module "discord.js" {
export interface Client {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
commands: Collection<unknown, any>
}
}
in /types/common/discord.d.ts however im still getting Property 'commands' does not exist on type 'Client<boolean>'. when trying to compile. DJS v14.2.0 NODE v16.10.0
21 replies