首页 > 解决方案 > 我如何邀请自己到我的不和谐机器人所在的服务器?

问题描述

我想找到一种方法来为我的机器人所在的每台服务器生成一个邀请链接,该链接将发送到我的帐户。但我不知道该怎么做。我有我的机器人所在的每台服务器的列表。我需要能够从命令提示符或作为基本功能生成邀请。这是在 python 3.9 中编码的。

标签: pythonpython-3.xdiscorddiscord.py

解决方案


您将不得不使用guild.create_invite内部on_ready循环所有行会。

编辑:您必须获得一个频道来创建邀请,在这种情况下,您将获得第一个文本频道并创建对它的邀请。

@bot.event
async def on_ready():
    print("Logged in as")
    print(bot.user.name)
    print("------")
    print(bot.owner_id)
    for guild in bot.guilds:
        channel = guild.text_channels[0] # get the first channel
        invite = await channel.create_invite(max_uses=1) # make the invite link
        user = bot.get_user(303069538315010058)  # place your ID here
        await user.send(invite.url)  # Send the invite to the use

推荐阅读