0

So, I was making my Discord bot as usual, and just at a moment this problem started popping up without any reason at all. It says the problem is caused by the end of the line, which is where my token is. I have no idea what exactly is causing it. I even looked at the code from the official Discord docs, everything should be right. Maybe I made a typo or something, no idea. I even regenerated the token itself multiple times and checked if it was right but it doesn't seem to work.

const fs = require('fs');
const Discord = require('discord.js');
const Client = new Discord.Client();

const client = new Discord.Client();
client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

const cooldowns = new Discord.Collection();

Client.on('ready', ()=>{
console.log("ready to go");
});

Client.on('message', message =>{
    if (!message.content.startsWith("e!") || message.author.bot) return;

    const args = message.content.slice("e!".length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    if (!client.commands.has(command)) return;

    try {
        client.commands.get(command).execute(message, args);
    } catch (error) {
        console.error(error);
        message.channel.send('An error happened while trying to execute that command. Consult the owner of the bot for possible fixes.');
}

Client.on('guildMemberAdd', member => {

  const channel = member.guild.channels.cache.find(ch => ch.name === 'general');

  if (!channel) return;

  channel.send(`Welcome to the server, ${member}`);

})

Client.login("My token");
3
  • Could you add the full error message along with its stack trace to the question? Commented Jul 17, 2020 at 13:31
  • SyntaxError: Unexpected end of input [90m at wrapSafe (internal/modules/cjs/loader.js:1054:16)[39m [90m at Module._compile (internal/modules/cjs/loader.js:1102:27)[39m [90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m [90m at Module.load (internal/modules/cjs/loader.js:986:32)[39m [90m at Function.Module._load (internal/modules/cjs/loader.js:879:14)[39m [90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m [90m at internal/main/run_main_module.js:17:47[39md Commented Jul 17, 2020 at 13:36
  • it seems like the problem with the library itself, I'm not sure as I'm pretty new to javascript Commented Jul 17, 2020 at 13:37

1 Answer 1

1

Placing this code into visual studio code instantly gave me this errorenter image description here

You seemed to have removed }) at the bottom of your file. I'd suggest using vscode as it tells you about these errors.

fixed code

const fs = require('fs');
const Discord = require('discord.js');
const Client = new Discord.Client();

const client = new Discord.Client();
client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

const cooldowns = new Discord.Collection();

Client.on('ready', () => {
    console.log("ready to go");
});

Client.on('message', message => {
    if (!message.content.startsWith("e!") || message.author.bot) return;

    const args = message.content.slice("e!".length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    if (!client.commands.has(command)) return;

    try {
        client.commands.get(command).execute(message, args);
    } catch (error) {
        console.error(error);
        message.channel.send('An error happened while trying to execute that command. Consult the owner of the bot for possible fixes.');
    }

    Client.on('guildMemberAdd', member => {

        const channel = member.guild.channels.cache.find(ch => ch.name === 'general');

        if (!channel) return;

        channel.send(`Welcome to the server, ${member}`);

    })
});

Client.login("My token");
Sign up to request clarification or add additional context in comments.

1 Comment

I probably removed it accidentally. Thank you very much. I will check vscode out thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.