#whenever i type node index.ts it doesnt show me any errors but bot doesnt get online

50 messages · Page 1 of 1 (latest)

atomic tulip

if it doesnt run with node what should it run with

nvm figured out

but got

ts-node : File C:\Users\j\AppData\Roaming\npm\ts-node.ps1 cannot be loaded because running scripts is disabled on this
system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • ts-node index.ts
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
grave finch

Don’t use ts-node… use tsc to transpile your typescript to JavaScript and run that

About the error you get there it explicitly mentions a URL to find help for it

atomic tulip

tsc : File C:\Users\f\AppData\Roaming\npm\tsc.ps1 cannot be loaded because running scripts is disabled on this system. For
more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • tsc index.ts
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
grave finch

For more information, see …

Maybe try reading what it tells you to read

atomic tulip

but whenever i do tsc index.ts poweshell goes to node and back to normal no errors token correct bot doesnt go online

sterile elk

tsc only compiles the files

You need to run node on the compiled files after that

atomic tulip

even if i do ts-node index.ts its the same thing

sterile elk

Wdym by "the same thing"

That your code runs but the bot is not online?

sterile elk

Try adding a console.log("something") at the top of your file and see if that is logged to the console

If not, the problem is that you didn't run correctly the command or you run the wrong command. Otherwise, the problem is in your code logic

atomic tulip

already did console.log(Logged in as ${client.user?.tag});

sterile elk

That's totally different

I said at the top of the file

atomic tulip

oh

atomic tulip

code logic

`import * as Discord from 'discord.js';
import * as dotenv from 'dotenv';
import axios, { AxiosResponse } from 'axios';
import fs from 'fs';

dotenv.config();

const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '1!';

// Event: Bot is ready
client.on('ready', () => {
console.log(Bot is online. Logged in as ${client.user?.tag});
});

// Event: Message received
client.on('messageCreate', async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift()?.toLowerCase();

if (command === 'generategame') {
const attachments = Array.from(message.attachments.values() as Iterable<Discord.MessageAttachment>);

if (attachments.length === 0) {
  message.channel.send('Please attach an RBXL file for the game generation.');
  return;
}

const rbxlAttachment = attachments[0];
const rbxlUrl = rbxlAttachment.url;
const rbxlPath = ./downloaded_${rbxlAttachment.name};

// Download the RBXL file
try {
  const response: AxiosResponse<any> = await axios.get(rbxlUrl, { responseType: 'stream' });
  response.data.pipe(fs.createWriteStream(rbxlPath));

  response.data.on('end', () => {
    message.channel.send(RBXL file downloaded: ${rbxlAttachment.name}`);
  });
} catch (error) {
  console.error(error);
  message.channel.send('Oops! Something went wrong while downloading the RBXL file.');
}

}
});

// Log in the bot using your token
client.login(process.env.DISCORD_TOKEN);`

is the code

but dont know whats wrong with the code logic

sterile elk

Can you use a codeblock? I can't understand anything if you send the code like this 😂

grave finch
atomic tulip

i already added the console log console.log(Bot is online. Logged in as ${client.user?.tag}); and runned it correctly and nothing happened

grave finch
tame deltaBOT
grave finch

What you do there works perfectly fine with keeping the message.attachments as a Collection, using its .size property and .first() method

atomic tulip
grave finch

Then you don’t really run that file if it doesn’t log anything when you have that at the top outside of any functions

atomic tulip

i used npx ts-node index.ts

grave finch

Okay, I‘m leaving now. Getting tired of having to refer you back to stuff that’s already said in this thread…

frigid glacier
atomic tulip

tsc compiles TS to JS. it doesn't make your code run! after compiling with tsc then you can run it with node index.js

atomic tulip

i did the node index.js nothing happened

frigid glacier

add console logs in your ts file, compile then run again to see what goes on

atomic tulip
sterile elk
atomic tulip

its working now

sorry for the problems