0

This is my discordbot i am trying to make but it keeps erroring at client.user.setPresence({ activities: [{ name: 'Test' }], status: 'online' });

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => res.send('Hello World!'));

app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));

// ================= START BOT CODE ===================
const Discord = require('discord.js');
const client = new Discord.Client();
const dcToken = process.env['DcT3enE4JJf']
  ;

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => {
  if (msg.content === '/ping') {
    msg.reply('Pong!');
  }

  if (msg.channel.id === '833702368637616191') {
      if (!msg.attachments.size) {
        msg.author.send(`Your message ("${msg}") was deleted, Please only send images in the #images channel`);
        msg.guild.channels.cache.get('883581919835615232').send(`A message "**${msg}**" by <@${msg.author.id}> was deleted from <#${msg.channel.id}>`);

        msg.delete()
        console.log('A message was deleted from #images')
      }
  }

});

client.login(dcToken);

client.user.setPresence({ activities: [{ name: 'Test' }], status: 'online' });

errors in the output

TypeError: Cannot read property 'setPresence' of null
    at /home/runner/DiscordBot1/index.js:38:13
    at Script.runInContext (vm.js:130:18)
    at Object.<anonymous> (/run_dir/interp.js:209:20)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

1 Answer 1

2

You can only do that after your bot is ready.

client.on('ready', () => {
   console.log(`Logged in as ${client.user.tag}!`);
   client.user.setPresence({ activities: [{ name: 'Test' }], status: 'online' });
});
Sign up to request clarification or add additional context in comments.

Comments

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.