简体   繁体   English

Discord.js - guild.member.get 返回未定义

[英]Discord.js - guild.member.get returning undefined

I've tried a lot of different methods of doing this.我已经尝试了很多不同的方法来做到这一点。 But I keep running into an issue where the user is returning undefined.但是我一直遇到用户返回未定义的问题。

TypeError: Cannot read property 'addRole' of undefined类型错误:无法读取未定义的属性“addRole”

code[1] is a discord id that I am passing through an embed which the bot is reading. code[1]是一个不和谐 ID,我正在通过机器人正在读取的嵌入。 The method I am trying at the moment, is getting the guild by id, then the member by id.我目前正在尝试的方法是通过 id 获取公会,然后通过 id 获取成员。 I did try message.guild but I was getting the same issue.我确实尝试过 message.guild 但我遇到了同样的问题。

When this runs on my ID, the add roll works.当它在我的 ID 上运行时,添加卷就起作用了。 However, when other members try, it returns undefined.但是,当其他成员尝试时,它返回 undefined。 Am I getting the member wrong?我弄错会员了吗?

var code = message.embeds[0].title.split( ":" );

let user_guilds = client.guilds.get( "453314772662878211" );
let user_member = user_guilds.members.get( code[1] );
    
user_member.addRole('455695410401640449');

Hopefully someone knows discord.js better than I do and can tell me what I'm doing wrong haha.希望有人比我更了解 discord.js 并且可以告诉我我做错了什么哈哈。 Thanks!谢谢!

现在使用 Discord.js 版本 v12 它的工作方式不同:addRole 现在是member.roles.add("role id ")

user_member.roles.add('roleid');

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

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