简体   繁体   English

获取提及用户的存在/活动

[英]Get presence/activity of mentioned user

I'm trying to create a command for my bot in Discord JS that when triggered, takes the command's mentioned user and retrieves their current game (If no game, then status) and sends a message saying Mentioned user has been playing Game for Time elapsed (And if possible, send the image of the game if it has one).我正在尝试在 Discord JS 中为我的机器人创建一个命令,当触发该命令时,会获取命令中提到的用户并检索他们当前的游戏(如果没有游戏,则为状态)并发送一条消息说提到的用户已经玩了一段时间游戏(如果可能,请发送游戏图像(如果有的话)。

This is my current code:这是我当前的代码:

module.exports = {
    name: 'game',
    aliases: ['gm', 'status'],
    category: 'Commands',
    utilisation: '{prefix}game',

    execute(client, message) {
        let msgMention = message.mentions.members.first() || message.guild.member(message.author)

        console.log(msgMention.presence.activities[0])

        message.channel.send(msgMention.presence.activities[0].name);
    },
};

All it does with the .name extension says name is undefined and if I remove .name it says cannot send an empty message.它对.name扩展名所做的一切都说 name 是未定义的,如果我删除.name它说不能发送空消息。 Also, I mention myself currently playing a game that so shown publicly on my discord activity status.另外,我提到我自己目前正在玩一个在我的 discord 活动状态上公开显示的游戏。 What can I do so it actually reads the name and time of the activity to then send it?我该怎么做才能真正读取活动的名称和时间然后发送它?

You need the GUILD_PRESENCES intent.您需要GUILD_PRESENCES意图。

const { Client, Intents } = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_PRESENCES] });

Also btw I'd recommend using message.member instead of message.guild.member(message.author)另外顺便说一句,我建议使用message.member而不是message.guild.member(message.author)

let msgMention = message.mentions.members.first() || message.member

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM