简体   繁体   English

Discord JS v13 - 从 discord js v13 中的用户标签获取内部用户 ID

[英]Discord JS v13 - Get internal user ID from a user tag in discord js v13

There have been similar questions but I havent been able to find an exact match so I apologize in advance.有类似的问题,但我无法找到完全匹配的,所以我提前道歉。

I have am application form that someone fills out and provides their discord user tag (ex: Bob#1111).我有一份申请表,有人填写并提供了他们的不和谐用户标签(例如:Bob#1111)。 This form then gets sent to my discord (which that user has already joined).然后,此表格会发送到我的不和谐(该用户已经加入)。 I then process it with my bot which creates a channel, copies the application to that channel and uses the discord user tag of the applicant to get their discord information and give them permissions on that newly created channel.然后我用我的机器人处理它,它创建一个频道,将应用程序复制到该频道,并使用申请人的不和谐用户标签来获取他们的不和谐信息并授予他们对该新创建频道的权限。

This worked for a few years prior to v13 but now its no longer working.这在 v13 之前工作了几年,但现在不再工作了。 Prior code was simply :之前的代码很简单:

await guild.members.fetch()
let userID = client.users.cache.find(user => user.tag === userTag)    

Any thoughts would be greatly appreciated.任何想法将不胜感激。

For what you're trying to do, I would recommend getting the member by their ID.对于您要执行的操作,我建议您通过 ID 获取成员。 You can do this by doing:你可以这样做:

const member = guild.members.fetch('user-id')

For your code, userID will in fact give you the entire user class, not just the ID.对于您的代码, userID实际上会为您提供整个用户类,而不仅仅是 ID。 You can access the user's ID by doing userID.id .您可以通过执行userID.id来访问用户的 ID。

If this does not work, please provide some more code and show me the error code you're receiving so I can better understand the problem.如果这不起作用,请提供更多代码并向我显示您收到的错误代码,以便我更好地理解问题。

Since you didn't explain what the actual issue is, I can only assume that the problem is when you try to give the user permissions for the channel.由于您没有解释实际问题是什么,我只能假设问题出在您尝试为用户授予频道权限时。

Make sure to find the member in your server:确保在您的服务器中找到该成员:

const member = await guild.members.cache.get(userID.id)

and then give the permissions for the found member.然后为找到的成员授予权限。

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

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