Reputation: 11
So I have this command that sets the bot's "Playing" status:
const commando = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
class sets extends commando.Command {
constructor(client) {
super(client, {
name: 'setgame',
group: 'owner',
memberName: 'setgame',
description: 'Sets the Bots\' activity',
examples: ['Playing __on many servers!__'],
args: [
{
key: "game",
prompt: "What do you want to set my game as?",
type: "string"
}
]
});
}
async run(message, { game } ) {
if (message.author.id !== "442918106378010635"){
message.channel.send("That's for TheRSC only!");
}
else {
this.client.bot.setActivity(game)
const embed = new RichEmbed()
.setColor(0x00AE86)
.setDescription("Game set!");
message.channel.send({embed});;
}
}
}
module.exports = sets;;
I ran into a few bugs before and managed to fix them, but this one stumps me. No matter how I code it, I keep getting: TypeError: Cannot read property 'setActivity' of undefined
I've tried a few things, having text be defined in run, putting args.game into .setActivity() and it keeps spitting out that error. I tried the splitting the args method but that didn't work either. Any ideas? (As a side note, I'd also like to turn this into a .setPresence command if possible.)
Note: I am a beginner at coding, so I may be doing something that the average coder wouldn't.
Upvotes: 1
Views: 8071
Reputation: 71
Try changing
client.bot.setActivity(game)
to
client.user.setActivity(game)
You can take a look at this example provided by the official documentation on setActivity() if you need more help, or if my solution doesn't work.
client.user.setActivity('YouTube', { type: 'WATCHING' })
.then(presence => console.log(`Activity set to ${presence.game ? presence.game.name : 'none'}`))
.catch(console.error);
EDIT: I still think it has something to do with the .bot
part because the only reference on the documentation of .bot
was a boolean of whether or not a user was a bot.
Upvotes: 1