无需用户交互的 Discord Bot 自动踢
Discord Bot Automated Kick with no user interaction
我正在编写一个机器人,它会在某个频道收到消息时启动踢球序列。它比较 Google Sheet 上的数据,以查找先前验证订阅但现在已取消的成员的用户 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
其实是await message.author.kick(cell_user, reason = "User unsubscribed")
不是await bot.kick(cell_user, reason = "User unsubscribed")
.
message.author.kick()
:踢掉channel_rcv
内发消息的成员。
bot.kick()
: 尝试踢机器人。
经过更多调查并在 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 Sheet 上的用户名中提取会员 ID,用于跟踪目的。这让我不需要指定作者或成员,因为这个函数不是用户输入的命令。
我正在编写一个机器人,它会在某个频道收到消息时启动踢球序列。它比较 Google Sheet 上的数据,以查找先前验证订阅但现在已取消的成员的用户 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
其实是await message.author.kick(cell_user, reason = "User unsubscribed")
不是await bot.kick(cell_user, reason = "User unsubscribed")
.
message.author.kick()
:踢掉channel_rcv
内发消息的成员。
bot.kick()
: 尝试踢机器人。
经过更多调查并在 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 Sheet 上的用户名中提取会员 ID,用于跟踪目的。这让我不需要指定作者或成员,因为这个函数不是用户输入的命令。