0
votes

im trying to find a way to send a message to a channel upon launch of the discord bot. I've tried using

client.on('message', (message) => {
client.on('ready', () => {
  channel = client.channels.cache.get('744630121213722696');
  channel.send('bot is up and running!');

})});

but no success, I get no error messages just no response from the bot

1
Remove the on('ready') handler from the on('message') handler. Consider: It is not possible to check for a bot's launch from inside any other kind of handler, since the bot's launch is the first handler. Don't nest event handlers. - Allister
You cannot place one event listener inside of another, this will cause a memory leak. - Elitezen

1 Answers

1
votes

You can't have 2 handlers in one. Take away the client.on('message', (message) => {}

So new code would be:

client.on('ready', () => {
  channel = client.channels.cache.get('744630121213722696');
  channel.send('bot is up and running!');

});