我正在创建一个事件来识别会员状态
I am creating an event to identify the Member Status
client.on('raw', async dados => {
if(dados.t == 'PRESENCE_UPDATE' && this.client.guilds.cache.get("948835296089342012").members.cache.get(dados.d.user.id)){
let membro = this.client.guilds.cache.get("948835296089342012").members.cache.get(dados.d.user.id)
if(dados.d.activites.state == null) return membro.roles.remove("653651520361070612")
if(dados.d.activities.state == undefined) return membro.roles.remove("653651520361070612")
let valor = dados.d.activities.state.toLowerCase()
let n = valor.search(`discord.gg/server`)
if(n>=0) membro.roles.add("653651520361070612")
if(n<0 && membro.roles.cache.has("653651520361070612")) membro.roles.remove("653651520361070612")
}
日志=
user: { id: '932194344859996180' },
status: 'online',
guild_id: '947899731303096320',
client_status: { web: 'online' },
activities: [
{
type: 4,
state: 'aa536a43',
name: 'Custom Status',
id: 'custom',
created_at: 1647655901662
}
]
}
我正在创建一个事件来识别成员的状态,例如:如果成员在 discord 中具有 url。gg/3 状态,则该成员将获得一个位置,当他移除时机器人将删除所选位置的状态
const Command = require("../../structures/Command");
module.exports = class teste extends Command {
constructor(client) {
super(client);
this.client = client;
this.name = "teste";
this.category = "Fun";
this.description = ".";
this.usage = "";
this.aliases = [];
this.enabled = true;
this.guildOnly = true;
}
async run({ message, args}, t) {
const user =
this.client.users.cache.get(args[0]) ||
message.mentions.members.first() ||
message.author
console.log(user.presence.activities.state)
}
}
我也尝试过在不基于事件的情况下使用它,但是在命令上,它总是returns未定义
日志=
[
Activity {
id: 'custom',
type: 'CUSTOM',
url: null,
details: null,
state: 'aa536a43',
applicationId: null,
syncId: null,
platform: null,
party: null,
assets: null,
flags: ActivityFlags { bitfield: 0 },
emoji: null,
sessionId: null,
buttons: [],
createdTimestamp: 1647656752595
}
]
存在仅在GuildMember not an user. Get the member who used the command from message.member
可用(确保该命令在公会中使用)
现在通过 message.member.presence
. Seems like you are trying to get member's custom status. It's one of presence.activities
array and has the type Activity
读取成员的状态。在那个类型为 CUSTOM
的数组中查找,这就是您所需要的。请注意,presence 可以为 null,因此您需要检查它是否存在。
这是我测试过的代码,它可以工作。希望它也适合你:
const member = message.member; // Get member from message
const custom = member.presence?.activities?.find(x => x?.type === 'CUSTOM'); // Get the custom status from member's presence
if (custom?.includes('cat') console.log('This user has `cat` in his/her custom status');
else { console.log('This user doesn\'t have `cat` in his/her custom status'); }
client.on('raw', async dados => {
if(dados.t == 'PRESENCE_UPDATE' && this.client.guilds.cache.get("948835296089342012").members.cache.get(dados.d.user.id)){
let membro = this.client.guilds.cache.get("948835296089342012").members.cache.get(dados.d.user.id)
if(dados.d.activites.state == null) return membro.roles.remove("653651520361070612")
if(dados.d.activities.state == undefined) return membro.roles.remove("653651520361070612")
let valor = dados.d.activities.state.toLowerCase()
let n = valor.search(`discord.gg/server`)
if(n>=0) membro.roles.add("653651520361070612")
if(n<0 && membro.roles.cache.has("653651520361070612")) membro.roles.remove("653651520361070612")
}
日志=
user: { id: '932194344859996180' },
status: 'online',
guild_id: '947899731303096320',
client_status: { web: 'online' },
activities: [
{
type: 4,
state: 'aa536a43',
name: 'Custom Status',
id: 'custom',
created_at: 1647655901662
}
]
}
我正在创建一个事件来识别成员的状态,例如:如果成员在 discord 中具有 url。gg/3 状态,则该成员将获得一个位置,当他移除时机器人将删除所选位置的状态
const Command = require("../../structures/Command");
module.exports = class teste extends Command {
constructor(client) {
super(client);
this.client = client;
this.name = "teste";
this.category = "Fun";
this.description = ".";
this.usage = "";
this.aliases = [];
this.enabled = true;
this.guildOnly = true;
}
async run({ message, args}, t) {
const user =
this.client.users.cache.get(args[0]) ||
message.mentions.members.first() ||
message.author
console.log(user.presence.activities.state)
}
}
我也尝试过在不基于事件的情况下使用它,但是在命令上,它总是returns未定义
日志=
[
Activity {
id: 'custom',
type: 'CUSTOM',
url: null,
details: null,
state: 'aa536a43',
applicationId: null,
syncId: null,
platform: null,
party: null,
assets: null,
flags: ActivityFlags { bitfield: 0 },
emoji: null,
sessionId: null,
buttons: [],
createdTimestamp: 1647656752595
}
]
存在仅在GuildMember not an user. Get the member who used the command from message.member
可用(确保该命令在公会中使用)
现在通过 message.member.presence
. Seems like you are trying to get member's custom status. It's one of presence.activities
array and has the type Activity
读取成员的状态。在那个类型为 CUSTOM
的数组中查找,这就是您所需要的。请注意,presence 可以为 null,因此您需要检查它是否存在。
这是我测试过的代码,它可以工作。希望它也适合你:
const member = message.member; // Get member from message
const custom = member.presence?.activities?.find(x => x?.type === 'CUSTOM'); // Get the custom status from member's presence
if (custom?.includes('cat') console.log('This user has `cat` in his/her custom status');
else { console.log('This user doesn\'t have `cat` in his/her custom status'); }