Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

node.js - How would one create a guild and then give myself an invite link

so I am currently in the process of trying to have a bot create a new guild/discord server and then console.log() an invite link for that so that I can join the guild and set it up to then invite friends. However, I am running into some slight problems as I am unsure as to how to go about this. My thought process is the following:

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);
}

My first problem is that I am not even sure if the guild creation is valid and how to get a guild invite from a guild object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have semi-completed what I wished to do. However, this is not the final thing because there is an error messaged:

    DiscordAPIError: Unknown Channel
    at RequestHandler.execute (C:Usersjonas
ode_modulesdiscord.jssrc
estRequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RequestHandler.push (C:Usersjonas
ode_modulesdiscord.jssrc
estRequestHandler.js:39:14) {
  method: 'post',
  path: '/channels/801898492082782310/invites',
  code: 10003,
  httpStatus: 404

I am unsure what the reason for the error in getting the correct channel but I'll reply to this with the full code when I have solved the problem.

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);

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...