我想获取拥有我的机器人的公会/服务器的所有邀请链接,该怎么办?
#include <iostream>
#include <math.h>
#include "wav.hpp"
#include <fstream>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
std::ifstream ifile("odetojoy.txt", std::ios::in);
std::vector<double> scores;
//check to see that the file was opened correctly:
if (!ifile.is_open()) {
std::cerr << "There was a problem opening the input file!\n";
exit(1);//exit or do additional error checking
}
double num = 0.0;
//keep storing values from the text file so long as data exists:
while (ifile >> num) {
scores.push_back(num);
}
//verify that the scores were stored correctly:
for (int i = 0; i < scores.size(); ++i) {
std::cout << scores[i] << std::endl;
仅输出服务器名称。我应该如何获取服务器的ID /邀请链接?
答案 0 :(得分:0)
如果要获取具有机器人的服务器的ID,只需遍历数组并打印guild.id
。例如:
var serverArray = client.guilds.array();
for(i = 0; i < serverArray.length; i++) {
print("Server ID: " + serverArray[i].id);
}
如果要获取到服务器的邀请链接,请使用guild.fetchInvites()
。示例:
var serverArray = client.guilds.array();
for(i = 0; i < serverArray.length; i++) {
serverArray[i].fetchInvites().then(invites => {
invites.map(invite => {
print("Invite link: " + invite.url);
});
});
}
请注意,上面的示例仅在实际有到服务器的邀请链接时才起作用。如果没有邀请链接,则可以使用GuildChannel.createInvite()
创建一个邀请链接。 https://discord.js.org/#/docs/main/11.6.4/class/GuildChannel?scrollTo=createInvite