簡體   English   中英

如何在 discord.js 中獲取 discord 服務器的名稱和圖片

[英]how to grab the name and picture of a discord server in discord.js

嗨,我想知道如何獲取 discord 邀請的服務器名稱。 示例https://discordapp.com/api/v6/invites/H4ySkbn ,其中H4ySkbn是服務器邀請碼

它會帶你到這樣的頁面打開鏈接后的頁面

這部分是我需要抓住的部分

在此處輸入圖像描述

我需要名稱和服務器配置文件圖片的原因是將其嵌入此 webhook

網絡掛鈎

如果有人知道使用 discord API 或其他方式執行此操作的方法,將不勝感激!

如果您使用 discord.js 您可以簡單地使用<Client>.fetchInvite()

const client = <Client>
client.fetchInvite(invite_url)
      .then(console.log);

這將返回一個 Invite 實例:

https://discord.js.org/#/docs/main/stable/class/Invite

之后只需通過.guild訪問公會:

const client = <Client>
client.fetchInvite(invite_url)
  .then(inv => {
    console.log(inv.guild);
    console.log(inv.guild.name, inv.guild.iconURL());
  });

If you want to use https://discordapp.com/api/v6/invites/H4ySkbn just fetch the link with axios or node-fetch resolve it in JSON and then access the properties there, but in that case the icon url will be一個 hash

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM