【问题标题】:If more than x, their values are如果大于 x,它们的值为
【发布时间】:2021-07-14 10:33:45
【问题描述】:

您好,我想在我的机器人中做某事,但我做不到,我需要您的帮助。我想要做的是“如果玩家大于 1,则将其置于机器人的状态”,恰恰相反。

代码在这里;

const presence = async () => {
    let res = await oyuncular("players");
    if (oyuncular >= 1)
    client.user.setPresence({activity: {name: `Sunucuda ${res.data.length} kişi`,type:"PLAYING"}, status:"dnd"}) //{name: `Turnuvada ${res.data.length} kişi`,type:"PLAYING"} --- {activity: {name: `Sunucuda ${res.data.length} kişi`,type:"PLAYING"}, status:"dnd"} --- {activity: {name: `Sunucu Bakımda!`,type:"PLAYING"}, status:"dnd"}
    if (oyuncular <= 1)
    client.user.setPresence({activity: {name: `Sunucu Kapalı`,type:"PLAYING"}, status:"dnd"})
    return;

}

【问题讨论】:

  • 当前的实现有什么问题?并且 res 变量不是保存您要检查的值吗?

标签: javascript node.js if-statement discord discord.js


【解决方案1】:

您犯的错误是您在if 语句中控制oyuncular。但是,函数内部或外部都没有名为oyuncular 的参数。如果你想控制玩家数量,你必须先得到这个值。

我不确定返回 await oyuncular("players") 的是什么,但我猜这个函数返回 players 数组。因此,如果您要检查数组长度。您可以获得oyuncuSayisi(活跃玩家数量)。

所以如果你可以试试这个功能将起作用:

const presence = async () => {
    let res = await oyuncular("players");
    var oyuncuSayisi = res.data.lenght;
    if (oyuncuSayisi >= 1)
    client.user.setPresence({activity: {name: `Sunucuda ${oyuncuSayisi} kişi`,type:"PLAYING"}, status:"dnd"}) //{name: `Turnuvada ${res.data.length} kişi`,type:"PLAYING"} --- {activity: {name: `Sunucuda ${res.data.length} kişi`,type:"PLAYING"}, status:"dnd"} --- {activity: {name: `Sunucu Bakımda!`,type:"PLAYING"}, status:"dnd"}
    if (oyuncuSayisi <= 1)
    client.user.setPresence({activity: {name: `Sunucu Kapalı`,type:"PLAYING"}, status:"dnd"})
    return;
}

【讨论】:

  • 您能否将res 对象的日志添加到您的问题中,好吗?在let res = await oyuncular("players"); 行下,console.log(res);
  • 我已经在这里定义了演员。它通过IP吸引了许多人。 Ekran Görüntüsü/Screenshot
  • 我看不到对象的名称。你能告诉我对象开始的部分吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-19
  • 2018-11-11
  • 1970-01-01
  • 2022-11-22
  • 2013-03-31
  • 1970-01-01
  • 2022-09-24
相关资源
最近更新 更多