如何创建特定数量的邀请链接,这些邀请链接只能在Python中用于Discord服务器一次

时间:2020-03-23 17:39:33

标签: python python-3.x discord

我是使用Discord服务器的新手,我想创建一个私有Discord服务器,只有我邀请的用户可以加入。我读到了一些可以实现这一目标的方法,但我想的都不是。我当时正在考虑创建一个Discord应用程序,该应用程序生成到服务器的特定数量的邀请链接,这些邀请链接只能使用一次。

这意味着,如果我想邀请50个人加入我的Discord服务器,我将创建50个只能使用一次的邀请链接,以便确保只有我邀请的人可以加入。我想将所有这些链接放在一个外部文本文件中,以便以后可以使用它们,并最终通过电子邮件将其发送给其他人。换句话说,我不需要创建机器人,而只需使用Python和discord.py模块即可在Discord之外实现所有这些功能。

我在discord.py文档中看到了this,看起来很像我需要的东西,但我真的不知道该如何工作。

我几乎只能在Discord服务器本身上找到有关如何创建机器人的教程,但这不是我所需要的。有人可以帮我吗?

非常感谢您!

1 个答案:

答案 0 :(得分:0)

import discord

token = 'bot_token_goes_here'
client = discord.Client()
number_of_links = input('How many links do you want to create? ') 

@client.event 
async def on_ready():
    g = client.guilds[guild_number goes here] # Choose the guild/server you want to use 
    c = g.get_channel(channel_id_goes_here) # Get channel ID
    invites = await discord.abc.GuildChannel.invites(c) # list of all the invites in the server

    while len(invites) < int(number_of_links):
        print('CREATING INVITES')
        for i in range(int(number_of_links)): # Create as many links as needed
            i = await discord.abc.GuildChannel.create_invite(c, max_uses=1, max_age=0, unique=True) # Create the invite link
        break

    print('Finished. Exiting soon...')
    exit()

client.run(token)