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

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

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

問(wèn)題描述

我有一個(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)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測(cè)圖像并響應(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ù))
主站蜘蛛池模板: 亚洲欧美日韩一区二区 | 国产黄色一区 | 91人人爽| 日韩中文字幕精品 | 亚洲三区在线 | 一区免费视频 | 黄色影视大全 | 欧美黑人一区二区三区 | 亚洲成人av在线 | 国产天天操 | 午夜精品国产精品大乳美女 | 午夜91| 国产三级视频在线播放 | 免费福利片 | 免费网站观看www在线观看 | 久久久久久久 | 国产成人精品免费视频 | 国产三级视频在线播放 | 久久99热这里只频精品6学生 | 亚洲精品黄色 | 伊人91 | 久久96| 亚洲资源站| 国产在线www| 午夜爽爽影院 | 国产a视频 | 久久精品在线 | 久久免费视频观看 | 欧美激情免费 | 欧美日韩在线看 | 日韩精品欧美 | a在线免费观看 | 黄色三级免费 | 亚洲自拍偷拍视频 | 日韩二区在线 | 手机在线看片1024 | 亚洲欧美日韩另类 | www.日韩精品| 欧美在线网址 | 少妇高潮久久久久久潘金莲 | 中文字幕一区二 |