【问题标题】:Is it possible, with a discord.js bot to know on which device is connected a user是否有可能通过 discord.js 机器人知道用户在哪个设备上连接
【发布时间】:2020-09-26 19:58:01
【问题描述】:

我想知道是否有可能让成员使用不和谐的设备(Web、桌面、移动应用程序)将其放入 userinfo 命令中。

感谢您的建议。

【问题讨论】:

  • 暂时不可以。
  • 如果有可能你需要做很多API Requests

标签: javascript node.js bots discord discord.js


【解决方案1】:

实际上,您可以使用公会的存在。确保read the docs

【讨论】:

  • 是的,实际上我不知道,但感谢 Tenclea,您可以使用 .clientStatus
【解决方案2】:

是的

client.on("消息", 异步消息 => { if (message.content.toLowerCase().startsWith('-device')){

const user = message.mentions.users.first();

let devices = [];

if (!user) {
  var status = message.author.presence.clientStatus;
} else {
  var status = user.presence.clientStatus;

  if (user.bot) {
    const webbot = new Discord.MessageEmbed()
    .setTitle(`${user.tag} device:`)
    .setDescription("web")

    message.channel.send(webbot)

    return;
  };
};

if (!status) {
  // status is unavailable
  const nostatus = new Discord.MessageEmbed()
    .setTitle(`${user.tag} device:`)
    .setDescription("unavaliable")

    message.channel.send(nostatus)

  return;
};

if (status.desktop) {
    devices.push('desktop');
};

if (status.web) {
    devices.push('web');
};

if (status.mobile) {
    devices.push('mobile');
};

devices = devices.join(', ') || 'None';

const dev = new Discord.MessageEmbed()
.setTitle(`${user.tag} device:`)
.setDescription(devices)

message.channel.send(dev)

// send message

} })

【讨论】:

    【解决方案3】:
    const Discord = require("discord.js");
    let member = message.mentions.members.first();
    
    function getDevice(GuildMember = Discord.GuildMember.prototype) {
    let userS = GuildMember.presence.clientStatus;
    if (userS) {
        if (GuildMember.user.bot) {
             return "Web";
        } else if (userS.desktop) {
            return "Computer";
        } else if (userS.mobile) {
            return "Mobile";
        } else if (userS.web) {
            return "Web";
        } else { return "unknown"; }
      } else { return "unknown" };
    } console.log(`User device is ${getDevice(member)}`);
    

    【讨论】:

    • 欢迎来到 Stack Overflow。当代码附有解释时,它会更有帮助。 Stack Overflow 是关于学习的,而不是提供 sn-ps 来盲目复制和粘贴。请编辑您的答案并解释它如何回答所提出的具体问题。见【如何回答】stackoverflow.com/questions/how-to-answer)
    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
    猜你喜欢
    • 2019-12-07
    • 1970-01-01
    • 2021-05-01
    • 2018-09-29
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多