![](/img/trans.png)
[英]how can I make my bot disconnect from voice after 15 seconds being idle in discord.js
[英]How can I make my bot change status every 10 seconds? (Online, Idle, DND) Discord.js
我想知道我是否可以将我的 Discord.js 机器人设置为每隔一段时间更改其在线状态,例如每 10 秒左右从在线切换到空闲、免打扰,然后再次返回在线,并永远重复。
这是我当前的状态代码:
bot.on("ready", ()=>{
bot.user.setPresence({activity: {name: 'IN REWORK!' }, status: `idle` })
.then(console.log)
.catch(console.error);
有更改活动但不能更改状态的解决方案,有人可以帮忙吗? - 谢谢。
使用setPresence
方法更新机器人活动,您可以包含status
参数来更新机器人状态。
bot.user.setPresense(
activity: {
name: 'IN WORK'
},
status: 'online' // online, idle, invisible, dnd
)
在javascript中,可以使用setTimeout
function在特定时间后运行function里面的代码。
var onlineStatus = 'online'
function statusLoop() {
setTimeout(() => {
if (onlineStatus === 'online') idleStatus();
statusLoop(); // schedule the next status update.
}, 10000) // Time in ms, 10000 ms = 10s
}
function onlineStatus() {
bot.user.setPresense(
activity: {
name: 'IN WORK'
},
status: 'online' // online, idle, invisible, dnd
)
onlineStatus = 'online'
}
statusLoop();
只需创建 function 的 rest,就完全一样了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.