【问题标题】:Discord Bot Automated Kick with no user interactionDiscord Bot 自动踢,无需用户交互
【发布时间】:2021-09-17 19:44:06
【问题描述】:

我正在编写一个机器人,它会在某个频道收到消息时启动踢球序列。它比较 Google 表格上的数据,以查找之前验证订阅但现在已取消订阅的成员的用户 ID。一切都在使用await bot.kick() 协程。我什至尝试定义另一个函数来调用以完成此操作。

我已阅读 API 文档,但无济于事。我的另一个选择是剥离订阅的访问角色并将其留给用户离开服务器或分配不同的角色并创建一个管理员命令,该命令必须偶尔运行以踢出具有该角色的人。

@bot.event
@bot_has_permissions(kick_members = True)
async def on_message(message):
    channel_rcv = channel_autoIO
    channel = bot.get_channel(channel_track)
    if message.channel.id == channel_rcv:
        print("This worked")
        await asyncio.sleep(5)
        await message.delete()
        await channel.send("User kick initiated")
        cell_tag = wks.find(unsubTag)
        if bool(cell_tag) == True:
            cell_tagadd = wks.cell(cell_tag[0].label)
            cell_left = cell_tagadd.neighbour('left')
            email = cell_left.value
            cell_list = wks_2.find(email)
            cell_address = cell_list[0].label
            cell_email = wks_2.cell(cell_address)
            cell_adj = cell_email.neighbour('left')
            cell_user = cell_adj.value
            print(cell_user)
            await channel.send("Kicking: " + cell_user)
            await bot.kick(cell_user, reason = "User unsubscribed")
        else:
            await channel.send("Error: Unsubscribed user not found. Please perform a manual verification and report discrepancies to @Developer")
    else:
        return

【问题讨论】:

    标签: python python-3.x discord bots


    【解决方案1】:

    经过更多调查并在 Discord.py 服务器上提出了一些问题,我能够解决我的问题!

    user_id = discord.Object(id = message.guild.get_member_named(cell_name).id)
    await message.guild.kick(user_id, reason = cell_name + reason)
    

    我使用discord.Object 从存储在我用于跟踪目的的 Google 表格中的用户名中提取会员 ID。这让我不需要指定作者或成员,因为此功能不是用户输入的命令。

    【讨论】:

      【解决方案2】:

      实际上是await message.author.kick(cell_user, reason = "User unsubscribed") 不是 await bot.kick(cell_user, reason = "User unsubscribed")

      message.author.kick():踢掉channel_rcv内部发送消息的成员。

      bot.kick(): 试图踢掉机器人。

      【讨论】:

      • 实际上我已经尝试过这种格式,它提供了这个:AttributeError: 'Message' object has no attribute 'member' 所以这实际上是行不通的。
      • 我的错,是message.author,而不是message.member
      猜你喜欢
      • 2020-12-18
      • 2021-04-20
      • 2022-01-04
      • 2021-10-16
      • 1970-01-01
      • 2012-04-02
      • 2022-01-21
      • 1970-01-01
      • 2020-05-16
      相关资源
      最近更新 更多