-2

所以我目前正在尝试让一个机器人创建一个新的公会/不和谐服务器,然后 console.log() 一个邀请链接,这样我就可以加入公会并将其设置为然后邀请朋友。但是,我遇到了一些小问题,因为我不确定如何去做。我的思考过程如下:

run : function(msg, client, cmds, disc, args){
    const guild = client.guild.create("New Guild");
    let invite //(and here get a new guild invite code )
    console.log(invite);
}

我的第一个问题是我什至不确定公会创建是否有效以及如何从公会对象获取公会邀请。

4

2 回答 2

0

我已经完成了我想做的事情。然而,这不是最后的事情,因为有一个错误消息:

    DiscordAPIError: Unknown Channel
    at RequestHandler.execute (C:\Users\jonas\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RequestHandler.push (C:\Users\jonas\node_modules\discord.js\src\rest\RequestHandler.js:39:14) {
  method: 'post',
  path: '/channels/801898492082782310/invites',
  code: 10003,
  httpStatus: 404

我不确定获取正确频道时出错的原因是什么,但是当我解决问题后,我会用完整的代码回复这个问题。

run : function(msg, client, cmds, disc, args){
        //console.log("1");
        client.guilds.create("New Guild")
            .then(value => {
                let channel = value.channels.cache.first();
                let invite = channel.createInvite({
                  maxAge: 0, // 0 = infinite expiration
                  maxUses: 0 // 0 = infinite uses
                })
                .then(result => {
                    console.log(result);
                })
                .catch(console.error);
                console.log(invite.url);
            })
            .catch(console.error);

}
于 2021-01-21T19:59:44.910 回答
0

The way I fixed it was that previously the object that it fetched was a category channel object meanwhile I needed a text channel/voice channel to create an invite. The solution I used was the following:

run : function(msg, client, cmds, disc, args){
        client.guilds.create("New Guild")
            .then(value => {
                value.channels.create('new-general', { reason: 'Needed a cool new channel' })
                .then(channel => {
                    let invite = channel.createInvite()
                        .then(invite => console.log(invite))
                        .catch(console.error);
                    console.log(invite.url);
                })
                .catch(console.error);
            })
            .catch(console.error);

    }

To explain the fix, I had to create a channel in the server to invite someone so before I created an invite I created a new channel and used the newly created channel as the channel for the invite.

于 2021-01-21T20:24:06.517 回答