久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 Discord.js 中的用戶名中查找用戶 ID?

How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
本文介紹了如何從 Discord.js 中的用戶名中查找用戶 ID?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)包含 Discord 用戶名(即 JohnDoe#1234)的 json 文件 (localJSON.json),并且需要從這些用戶名中獲取用戶 ID 才能添加角色.我在網(wǎng)上查看的每個(gè)地方都導(dǎo)致 rMember 的值為未定義"或空".驗(yàn)證添加角色的代碼在給定用戶 ID 作為字符串時(shí)有效,但找不到如何從用戶名獲取用戶 ID.如何使用 Discord.js 從用戶名中獲取用戶 ID?

I have a json file (localJSON.json) with Discord usernames (i.e. JohnDoe#1234) and need to get the User IDs from these usernames in order to have a role added. Every place I have looked online has resulted with either an 'undefined' or 'null' value for rMember. Verified that the code to add a role works when given a User ID as a string, but can't find how to get a User ID from a username. How do I get a user's ID from their Username using Discord.js?

localJSON.json
[
  {
    "discordName": "JohnDoe#1234"
  },
  {
    "discordName": "MarySue#5678"
  }
]

function addRole(discordUsername, gameName, message){
  var roleName = "";
  //Switch statement to assign roleName to a valid guild role based on argument

  var userID = discordUsername.id; //Pseudo code, Need to accomplish this

  var rMember = message.guild.members.get(userID); //Needs UserID as string
  var gRole = message.guild.roles.find((role) => role.name == roleName); 
  if (!rMember) { //if member not in server
    message.channel.send(rMember + " is not in the server!");
  } else { //assign role
    rMember.addRole(gRole);
  }
}

async run(message, args){
  ...
  for (var i = 0; i < localJSON.length; i++) {
     var currentEntry = localJSON[i];
     var currrentUserName = currentEntry.discordName;
     addRole(currrentUserName, args, message); //addRole(discordUsername, gameName, message);
  }
}

推薦答案

你會(huì)想做的

client.users.cache.find(u => u.tag === 'Someone#1234').id

Discord.js v12 現(xiàn)在使用 .cache,所以你必須在緩存上運(yùn)行 find,并且 v12 還刪除了 Collection#find(key, value) 有利于Collection#find(data => data.key === value).

Discord.js v12 uses .cache now, so you have to run find on the cache, and v12 also removes Collection#find(key, value) in favor of Collection#find(data => data.key === value).

這篇關(guān)于如何從 Discord.js 中的用戶名中查找用戶 ID?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應(yīng))
Check if user ID exists in Discord server(檢查 Discord 服務(wù)器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會(huì)成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創(chuàng)建我的第一個(gè)機(jī)器人,但總是錯(cuò)誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機(jī)器人編寫事件/命令處理程序?)
DeprecationWarning: Collection#find: pass a function instead(DeprecationWarning: Collection#find: 傳遞一個(gè)函數(shù))
主站蜘蛛池模板: 不卡一区二区三区四区 | 精品久久久久久亚洲国产800 | 亚洲精品久久区二区三区蜜桃臀 | 亚洲综合99 | 亚洲自拍一区在线观看 | 精品国产乱码久久久久久蜜臀 | 亚洲成人在线视频播放 | 福利片在线观看 | 在线播放一区二区三区 | 综合自拍 | 你懂的av| 久久久久久久国产 | 日本久草视频 | 久草青青草 | 91精品国产一区二区三区 | 成人免费精品视频 | 密室大逃脱第六季大神版在线观看 | 成人亚洲精品久久久久软件 | 男人久久天堂 | 91pron在线 | 午夜小电影 | 不卡视频一区 | 免费在线观看一区二区 | 国产精品欧美一区二区三区 | 91久久久久 | 国产视频1| 久草新在线 | 亚洲成av人片在线观看无码 | 日韩精品二区 | 97视频在线观看免费 | 久久9久| 91精品国产一区二区在线观看 | 黄色片在线 | 日本中文在线 | 亚洲成人一区二区在线 | 视频在线一区二区 | 久久久一区二区三区 | 91精品一区二区三区久久久久久 | 国产精品久久久久久久久久不蜜臀 | 日韩一区二区三区av | 一本在线 |