SlashCommandBuilder is not defined in compiled TypeScript, but the TypeScript file acts like it is

Hi everybody, I'm pretty new to TypeScript and wanted to migrate my bot to use it instead of JavaScript. No errors in the compiler (well, one intentional), and everything looks fine. When starting up my bot, however, it immediately crashes and says that SlashCommandBuilder is not defined. All other signs say it is defined. I am using a command handler slightly modified from the one in discordjs.guide.
6 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Dominic
Dominic2y ago
I would appreciate being pinged if you reply :)
Superchupu
Superchupu2y ago
can you show your ts code that compiles and js code that fails
Dominic
Dominic2y ago
Sure, just a second The full error:
ReferenceError: SlashCommandBuilder is not defined
at Object.<anonymous> (/workspaces/vacuum/built/commands/dev-tools.js:39:15)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Client.<anonymous> (/workspaces/vacuum/built/index.js:110:23)
at Object.onceWrapper (node:events:628:26)
at Client.emit (node:events:513:28)
ReferenceError: SlashCommandBuilder is not defined
at Object.<anonymous> (/workspaces/vacuum/built/commands/dev-tools.js:39:15)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Module.require (node:internal/modules/cjs/loader:1028:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Client.<anonymous> (/workspaces/vacuum/built/index.js:110:23)
at Object.onceWrapper (node:events:628:26)
at Client.emit (node:events:513:28)
TypeScript code (SlashCommandBuilder is already defined in index.ts, I can show some of that if it would be helpful)
const developers = ["606526727753170969"];

module.exports = {
data: new SlashCommandBuilder()
.setName("dev-tools")
.setDescription(`It's a secret...`),
async execute(interaction) {
if (!developers.includes(interaction.user.id)) {
[...]
const developers = ["606526727753170969"];

module.exports = {
data: new SlashCommandBuilder()
.setName("dev-tools")
.setDescription(`It's a secret...`),
async execute(interaction) {
if (!developers.includes(interaction.user.id)) {
[...]
JS compiled version:
var developers = ["606526727753170969"];
module.exports = {
data: new SlashCommandBuilder()
.setName("dev-tools")
.setDescription("It's a secret..."),
execute: function (interaction) {
return __awaiter(this, void 0, void 0, function () {
var devToolsEmbed, devToolsRow;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!developers.includes(interaction.user.id)) return [3 /*break*/, 1];
[...]
var developers = ["606526727753170969"];
module.exports = {
data: new SlashCommandBuilder()
.setName("dev-tools")
.setDescription("It's a secret..."),
execute: function (interaction) {
return __awaiter(this, void 0, void 0, function () {
var devToolsEmbed, devToolsRow;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!developers.includes(interaction.user.id)) return [3 /*break*/, 1];
[...]
@qjuh @superchupu I can provide more if needed I just wasn't sure if it was I had it in them both and it complained that it was already defined?
Dominic
Dominic2y ago
Dominic
Dominic2y ago
however the compiler doesn't complain about that... const { SlashCommandBuilder } = require ("discord.js");, as I was doing before. I'm not sure what block-scoped means, do I need to do this some other way with typescript? As I said I'm quite new to typescript 😆 Will do. Thanks.