#whenever i type node index.ts it doesnt show me any errors but bot doesnt get online
50 messages · Page 1 of 1 (latest)
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
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
how about me enabling the error of script
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
For more information, see …
Maybe try reading what it tells you to read
k fixed that
but whenever i do tsc index.ts poweshell goes to node and back to normal no errors token correct bot doesnt go online
tsc only compiles the files
You need to run node on the compiled files after that
even if i do ts-node index.ts its the same thing
Wdym by "the same thing"
That your code runs but the bot is not online?
yes
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
already did console.log(Logged in as ${client.user?.tag});
That's totally different
I said at the top of the file
oh
yep
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
Can you use a codeblock? I can't understand anything if you send the code like this 😂
Sending your code doesn’t change what they suggested👆
.
i already added the console log console.log(Bot is online. Logged in as ${client.user?.tag}); and runned it correctly and nothing happened
👆do I really need to repeat the whole conversation?
Converting a Collection to an array
You only need to convert it to an array if you need the index of an entry:
• Iteration (looping) is possible with for...of over Collection#values or forEach
• You can transform a Collection to an array with Collection#map
• If you need indices, you can get the array using [...collection.values()]
What you do there works perfectly fine with keeping the message.attachments as a Collection, using its .size property and .first() method
did it top of the file and same results
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
i used npx ts-node index.ts
Okay, I‘m leaving now. Getting tired of having to refer you back to stuff that’s already said in this thread…
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
i did the node index.js nothing happened
add console logs in your ts file, compile then run again to see what goes on
added console logs ran again nothing happened
You didn't even save the file 💀
i realised that 5 mins ago
its working now
sorry for the problems