keppy
DIAdiscord.js - Imagine an app
•Created by keppy on 7/21/2023 in #djs-questions
How to make Typescript recognize type files
thx so much
7 replies
DIAdiscord.js - Imagine an app
•Created by keppy on 7/21/2023 in #djs-questions
How to make Typescript recognize type files
Wow, It seems that there was some fundamental misunderstanding!
7 replies
DIAdiscord.js - Imagine an app
•Created by keppy on 7/21/2023 in #djs-questions
How to make Typescript recognize type files
import {
Message,
Client,
Collection,
Events,
GatewayIntentBits,
TextChannel,
} from "discord.js"
import "./@types/client.d.ts"
import fs from "node:fs"
import path from "node:path"
import dotenv from "dotenv"
import { logMessage } from "./logger"
import { Achievement } from "./achievement"
import { JsonDB } from "./bombiesSqlite3"
dotenv.config()
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
})
client.once("ready", () => {
console.log("Ready!")
if (client.user) {
console.log(client.user.tag)
}
new JsonDB("roles", "achievements").createTable()
const achivement = new Achievement("1234567890").overwrite(
"",
[],
false,
null,
""
)
new Achievement("1234567890").get()
})
client.commands = new Collection()
const commandsPath = path.join(__dirname, "commands")
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"))
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
const command = require(filePath)
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command)
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
)
}
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.on("messageCreate", async (message: Message) => {
if (message.author.bot) return
// Message Logs
if (message.channel instanceof TextChannel) {
console.log(new logMessage(message, message.channel).saveOnFile())
}
// Message Response
if (message.content.startsWith("!ping")) {
message.channel.send("Pong!")
}
})
client.login(process.env.TOKEN)
import {
Message,
Client,
Collection,
Events,
GatewayIntentBits,
TextChannel,
} from "discord.js"
import "./@types/client.d.ts"
import fs from "node:fs"
import path from "node:path"
import dotenv from "dotenv"
import { logMessage } from "./logger"
import { Achievement } from "./achievement"
import { JsonDB } from "./bombiesSqlite3"
dotenv.config()
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
})
client.once("ready", () => {
console.log("Ready!")
if (client.user) {
console.log(client.user.tag)
}
new JsonDB("roles", "achievements").createTable()
const achivement = new Achievement("1234567890").overwrite(
"",
[],
false,
null,
""
)
new Achievement("1234567890").get()
})
client.commands = new Collection()
const commandsPath = path.join(__dirname, "commands")
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"))
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
const command = require(filePath)
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command)
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
)
}
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.on("messageCreate", async (message: Message) => {
if (message.author.bot) return
// Message Logs
if (message.channel instanceof TextChannel) {
console.log(new logMessage(message, message.channel).saveOnFile())
}
// Message Response
if (message.content.startsWith("!ping")) {
message.channel.send("Pong!")
}
})
client.login(process.env.TOKEN)
7 replies
DIAdiscord.js - Imagine an app
•Created by keppy on 7/21/2023 in #djs-questions
How to make Typescript recognize type files
$ npm run test
Debugger attached.
> [email protected] test
> ts-node --files src/main.ts
Debugger attached.
/home/keppy/bombies/node_modules/ts-node/src/index.ts:1085
throw new TypeError(
^
TypeError: Unable to require file: src/@types/client.d.ts
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or other executable extension with loader attached before `ts-node` available.
at getOutput (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1085:17)
at Object.compile (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/keppy/bombies/src/main.ts:9:1)
Waiting for the debugger to disconnect...
Waiting for the debugger to disconnect...
$
$ npm run test
Debugger attached.
> [email protected] test
> ts-node --files src/main.ts
Debugger attached.
/home/keppy/bombies/node_modules/ts-node/src/index.ts:1085
throw new TypeError(
^
TypeError: Unable to require file: src/@types/client.d.ts
This is usually the result of a faulty configuration or import. Make sure there is a `.js`, `.json` or other executable extension with loader attached before `ts-node` available.
at getOutput (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1085:17)
at Object.compile (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/home/keppy/bombies/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/keppy/bombies/src/main.ts:9:1)
Waiting for the debugger to disconnect...
Waiting for the debugger to disconnect...
$
7 replies
DIAdiscord.js - Imagine an app
•Created by keppy on 7/21/2023 in #djs-questions
How to make Typescript recognize type files
thx replying, but it does not run with error... (in only strict mode?)
7 replies