Hey everyone! I’m new to making Discord bots and I’m stuck. I’ve tried following a bunch of tutorials but my code still won’t work. Here’s what I’ve got so far:
const { token } = require('./secretStuff.json');
const botClient = new BotClient({ intentions: [Intentions.FLAGS.SERVERS] });
botClient.once('activated', () => {
console.log('Bot is up and running!');
});
botClient.activate(mySecretTokenHere);
When I try to run it, I get this error:
Error: Can't find module './secretStuff.json'
I’m totally lost. What am I doing wrong? Any help would be awesome!
I’ve encountered similar issues before. The error suggests the ‘secretStuff.json’ file isn’t where your code expects it to be. First, verify the file exists and is correctly named. If that’s not the issue, try using an absolute path instead of a relative one. Also, ensure you’re running the script from the correct directory. If problems persist, consider hardcoding the token temporarily for testing purposes. Remember to remove it before pushing to any public repositories. Lastly, double-check your Discord developer portal settings to ensure your bot has the necessary permissions.
hey john, looks like ur file path might be off. make sure ‘secretStuff.json’ is in the same folder as ur script. also, double-check if u named it exactly like that (caps sensitive). if its still not workin, try using the full path to the file. hope this helps!
I ran into this exact problem when I first started with Discord bots. The issue is likely with your file structure or how you’re running the script. Make sure you’re in the right directory when you execute the code. Also, double-check that ‘secretStuff.json’ is actually in the same folder as your main script.
One thing that helped me was using the ‘__dirname’ variable to get the absolute path. Try changing your require line to:
const { token } = require(__dirname + ‘/secretStuff.json’);
This ensures Node.js looks in the correct directory, regardless of where you’re running the script from.
If that doesn’t work, there might be an issue with your JSON file itself. Make sure it’s properly formatted and the ‘token’ key exists. Good luck with your bot!