Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

Discord bot code keeps getting errors. (JS)

I'm trying to code a Discord bot and I have never done that before so this is very new to me. But whatever I do to the code there is ALWAYS an error. It keeps saying in the text editor that nothing is wrong but when I start the code and debug it using Node.js it says unexpected token } or unexpected token ), I just don't know why it says that.

const Discord = require('discord.js');
const { prefix, token, bs } = require('./config.json');
const client = new Discord.Client();

client.once('ready', () => {
    console.log('Ready!');
});

const exampleEmbed = new Discord.MessageEmbed().setTitle('Epic programmer and super cool :)');

client.on('message', message => {
    if (message.content === `${prefix}ping`) {
        message.channel.send('Pong.');
    } else if (message.content === `${prefix}beep`) {
        message.channel.send('Boop.');
    } else if (message.content === `${prefix}server`) {
        message.channel.send({ embed: exampleEmbed.setTitle(`Server name: ${message.guild.name}
Total members: ${message.guild.memberCount}`) });
    } else if (message.content === `${prefix}user-info`) {
        message.channel.send({ embed: exampleEmbed.setTitle(`Your username: ${message.author.username}
Your ID: ${message.author.id}`) });
    } else if (message.content === `Cable creepersaur`) {
        message.channel.send({ embed: exampleEmbed.setTitle('Epic programmer and super cool :)') });
    } else if (message.content === `${prefix}commands`) {
        message.channel.send({ embed: exampleEmbed.setTitle(`c!ping
c!beep
c!server
c!user-info
Cable creepersaur
c!box`) });
    } else if (message.content === `${prefix}box`) {
        message.channel.send({ embed: exampleEmbed.setTitle(`??????????????????
???????????
???????????
???????????
??????????????????`) }).then(function (myMessage) {
            myMessage.react("??")
            .then(myMessage.react("??"));
        });

    }
});

client.login(token);

I keep trying to remove and add some } and ) brackets but it never works. It worked really well before and now that I tried to add a custom emoji it doesn't work. (I removed the custom emoji after).

This is the entire error message:

Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:1109
    throw err;
    ^

SyntaxError: c:UsersmathurDesktopCableBotconfig.json: Unexpected token } in JSON at position 95
    at parse (<anonymous>)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:1106:22)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (c:UsersmathurDesktopCableBotCable.js:2:31)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
Process exited with code 1

I am using Visual Studio code on windows. I don't know if that affects anything but I know that debugging and showing what you did wrong is different on different Text editors.

question from:https://stackoverflow.com/questions/65876159/discord-bot-code-keeps-getting-errors-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...