【问题标题】:Discord.py | Can a bot generate a Server Invite Link?不和谐.py |机器人可以生成服务器邀请链接吗?
【发布时间】:2021-04-22 11:24:54
【问题描述】:

我想知道机器人是否有可能生成 Discord 服务器链接。基本上,在我 UnBan 一个不和谐用户之后,我希望机器人邀请他回来。我还没有尝试过任何东西。我在谷歌上搜索但找不到任何东西。

(注意:我使用的是最新版本的 Discord.py。)

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:

    您可以将以下内容添加到您的 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() 方法的可选参数。

    Reference of method create_invite

    【讨论】:

    • 是的,我这样做了,但它似乎没有发送邀请链接。它似乎根本不起作用。 unban 命令工作得很好,嵌入也很好。但是当涉及到邀请时,它根本不起作用。注意:我正在使用 ID 解禁,这可能是问题吗?
    • 正如我所说,您需要先获取用户,如果您有他的 ID,您可以使用 fetch_user(),或者如果该用户已经在缓存中,则使用 get_user()
    • 哦,所以基本上我会做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) 内部。我要怎么定义它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2021-11-10
    • 1970-01-01
    • 2020-06-20
    • 2021-08-11
    • 2020-10-01
    • 2019-10-29
    相关资源
    最近更新 更多