【发布时间】:2021-04-22 11:24:54
【问题描述】:
我想知道机器人是否有可能生成 Discord 服务器链接。基本上,在我 UnBan 一个不和谐用户之后,我希望机器人邀请他回来。我还没有尝试过任何东西。我在谷歌上搜索但找不到任何东西。
(注意:我使用的是最新版本的 Discord.py。)
【问题讨论】:
标签: python python-3.x discord discord.py discord.py-rewrite
我想知道机器人是否有可能生成 Discord 服务器链接。基本上,在我 UnBan 一个不和谐用户之后,我希望机器人邀请他回来。我还没有尝试过任何东西。我在谷歌上搜索但找不到任何东西。
(注意:我使用的是最新版本的 Discord.py。)
【问题讨论】:
标签: python python-3.x discord discord.py discord.py-rewrite
您可以将以下内容添加到您的 Unban 命令中,为该特定 文本频道 创建不和谐邀请,然后将其发送给被取消禁止的用户:
# This will create the invite
invite = await ctx.channel.create_invite()
# This will send the user the invite via Private Message
# You will need to have fetched the user previously
await user.send(invite)
您可能还想检查official discord.py documentation 以检查可以传递给create_invite() 方法的可选参数。
【讨论】:
invite = await ctx.message.channel.create_invite() await fetch_user(user_id) await user.send(invite)?
await user.send(invite)。这是因为 fetch_user 返回用户并且不保存到缓存中而是保存到变量中。编辑:另外,我认为你必须在 bot 对象上调用 fetch_user,await bot.fetch_user() 但我不完全确定
user_id,它位于await fetch_user(user_id) 内部。我要怎么定义它?