繁体   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