python - 我如何邀请自己到我的不和谐机器人所在的服务器?
问题描述
我想找到一种方法来为我的机器人所在的每台服务器生成一个邀请链接,该链接将发送到我的帐户。但我不知道该怎么做。我有我的机器人所在的每台服务器的列表。我需要能够从命令提示符或作为基本功能生成邀请。这是在 python 3.9 中编码的。
解决方案
您将不得不使用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
推荐阅读
- javascript - 反应js。不能'获取未定义的值,用户的显示名称。我已使用道具来使用此文件中的用户状态,但它无法访问任何用户数据
- python - 如何在 MySQL 中复制 pandas 函数?
- python - 如何在 python 中使用正则表达式从字符串中获取某人的姓名?
- r - 如何在字符串中删除初始句点之前的文本、初始句点本身和最后句点之后的文本?
- c - 使用 (*variable).member 与 *variable.member 取消引用结构 Struct_type 的成员
- windows - PyCharm 的两个实例
- css - CSS 性能,#id vs .class vs [^regex$] vs 选择器
- python - 将一列'int'转换为'string'
- spring - Spring MVC - Dispatcher Servlet 找不到任何页面
- c++ - clang:发射是什么意思?