[英]Hibernate Discord bot discord.js
我正在尝试制作 hibernate 模式,其中机器人不做任何事情,但它保持在线。 我在下面写了一些东西
let configstuffs = JSON.parse(fs.readFileSync('config.json')) //figuring out if hibernate mode is on
if (configstuffs.hibernate === true) {
client.user.setPresence({ status: 'idle' })
client.user.setActivity('Bot is hibernating')
console.log('hibernating')
return
} else {
client.user.setPresence({ status: 'online' })
client.user.setActivity('')
console.log('no longer hibernating')
}
我把它放在我的消息监听器之外,在我的bot.once('ready', () => {}
里面,但它说的是'无法读取 null 的属性'setPresence'。
我的目标是,当 hibernate 模式处于活动状态时,机器人会变得空闲,并将其游戏设置为“休眠”或类似的东西,然后忽略所有消息,或绕过消息侦听器。 有人有什么想法吗?
我的机器人中有一个 hibernate 选项,这就是我所做的
let isHibernating = false; //Global (top level) variable
const Hibernate = (client) => {
if(!client){ return(false) }
client.user.setPresence({ //Sets detailed presence
activity: {
name: "Hibernating",
type: "PLAYING"
},
status: "idle",
afk: true
});
isHibernating = true;
}
在你的消息处理程序中
client.on("message", message => {
if(isHibernating){ return(false) } //Bot is Hibernating
// other things
if(message.content === "hibernate" && message.author.id == "Bot owner ID"){
Hibernate(client);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.