如何检查Discord.js上的邀请链接是否有效?

时间:2020-11-02 14:32:53

标签: discord discord.js

如何让漫游器检查某个频道(很多频道)上发布的邀请链接是否有效?我在这里搜索过Google,github和Discord服务器,但找不到答案。.我正在用Discord.js编写机器人代码,任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

如评论中所建议,您应该使用invite endpoint。您可以使用首选方法创建GET请求,但这是node-fetch的示例:

const fetch = require('node-fetch');

const code = 'this-is-invalid';

fetch(`https://discordapp.com/api/invite/${code}`)
 .then((res) => res.json())
 .then((json) => {
  if (json.message === 'Unknown Invite') {
   // the invite is invalid
  } else {
   // the invite is valid
  }
 });

Here's what the result object looks like