我遇到一些错误:
TypeError: Cannot read property 'user' of undefined
TypeError: Cannot read property 'guilds' of undefined
我可能还有其他一些尚未发现的错误。
如何解决这些错误?
这是我的Discord机器人的代码:
console.log("hi");
const { RichEmbed } = require("discord.js");
const randomPuppy = require("random-puppy");
const Discord = require('discord.js');
const client = new Discord.Client();
const token = 'token';
client.on('ready', async client => {
console.log('This bot is online');
client.user.setActivity("Youtube", {type: "Watching"})
client.guilds.cache.forEach((guild) => {
console.log(guild.name)
guild.channels.cache.forEach((channel) => {
console.log(` - ${channel.name} ${channel.type} ${channel.id}`)
})
//general text id: 721950719657115750
})
const jpg = "https://cdn.discordapp.com/attachments/709199176562638849/722646217930178620/OIPK7JS66QT.jpg"
const img = await randomPuppy(jpg);
const embed = new RichEmbed()
.setColor("RANDOM")
.setImage(img)
.setTitle(`From /r/${random}`)
.setURL(`https://reddit.com/r/${random}`);
message.channel.send(embed);
})
client.on('message', msg=>{
if(msg.content === "hello"){
msg.reply('hello')
}
})
client.login(token);
答案 0 :(得分:0)
尝试
client.user.setPresence({
activity: {name: 'Youtube'},
status: 'Watching'
})