Reputation: 87
This is by far the weirdest problem I ran in so far developing my Discord bot. This bot uses Discord.js.
I use a simple client.on('ready', () => {}) client.login(<token goes here>)
thing, the default. But somehow, the console doesn't give me an error, nor any logs, but it also doesn't do anything. Please take a look at my code:
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
//-------------------------------------------
const UserDataModel = require(`./data/userdata`);
const InventoryModel = require(`./data/inventory`);
const { connect } = require(`mongoose`);
client.on('ready', () => {
console.log('Bot online!');
});
client.on('message', async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
//more code down below
}
(async () => {
await connect(`mongodb://localhost/discord-bot`, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true
});
client.login(token);
});
As you can see, I use MongoDB for the data storage. Maybe it is a config problem, but I don't know how to fix such problems after much time spent on searching around. Any type of help is much appreciated! If additional code is needed, comment which part you need.
Upvotes: 0
Views: 1393
Reputation:
You have an anonymous which never executes
(async () => {
await connect(`mongodb://localhost/discord-bot`, {
useNewUrlParser: true,
useFindAndModify: false,
useUnifiedTopology: true
});
client.login(token);
})();
Should work
Upvotes: 2