Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.js setGame() not working anymore

I have been coding my Discord bot using Discord.JS for about 2 months now and I've just recently noticed that my bot isn't saying that it's playing what I'm telling it. When I first coded the bot up until recently it worked just fine. Now the 3 discord bots I have aren't showing their games.

This is the code I'm using:

const Discord = require("discord.js");
const bot = new Discord.Client();
bot.on("ready", () => {
  console.log("Ready");
  bot.user.setGame("Type !help");
}
like image 814
PMCJohn Avatar asked Aug 27 '17 18:08

PMCJohn


People also ask

Is Javascript good for discord bot?

discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.

How do I enable discord Bot in node JS?

Step 1: Create an App in Discord Once you're logged in, click on 'New Application' at the top right of the window. Then fill in the details of your app (i.e. name) and you will be taken to your app's dashboard. Navigate to 'Bot' and click 'Add Bot' to enable your app as a bot.


4 Answers

.setGame() is deprecated now but you could use .setPresence() or you could use the .setActivity() which is the same thing and format as the .setGame(). Ex.

const Discord = require('discord.js');
const bot = new Discord.Client();
bot.user.setActivity('YouTube', { type: 'WATCHING' });

Here is a link to the documentation in case you wanted to change 'Watching' to something else like 'Playing'.

like image 58
NintendoZaedus Avatar answered Sep 26 '22 14:09

NintendoZaedus


setGame() is now deprecated, and discord.js asks you to use setActivity().

const Discord = require("discord.js");
const bot = new Discord.Client();
bot.on("ready", () => {
  console.log("Ready");
  bot.user.setActivity("Type !help");
})

Hope this helped.

like image 21
Pruina Tempestatis Avatar answered Sep 26 '22 14:09

Pruina Tempestatis


The setGame() Method has stopped working, here's what you can do:

  • update to latest 11.1-dev or
  • use .setPresence({ game: { name: 'nameGoesHere', type: 0 } }); as a workaround instead

Source: https://github.com/hydrabolt/discord.js/issues/1807#issuecomment-323578919

like image 30
LW001 Avatar answered Sep 22 '22 14:09

LW001


Here's a short example of using the .setPresence that LW001 linked to:

var Discord = require('discord.js');
var bot = new Discord.Client();

bot.on('ready', () => {
    bot.user.setStatus('available') // Can be 'available', 'idle', 'dnd', or 'invisible'
    bot.user.setPresence({
        game: {
            name: 'Type !help',
            type: 0
        }
    });
});

https://discord.js.org/#/docs/main/stable/class/ClientUser?scrollTo=setGame

like image 33
koubi Avatar answered Sep 25 '22 14:09

koubi