在另一个函数中调用discord bot函数

2024-10-01 07:10:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个投票踢机器人,一旦计算了一定数量的投票,它就会踢用户。我想调用votekick函数中的kick函数。我正在学习python和discord机器人。我已经看了几个小时的文档了,还是弄不懂

@client.command()
async def kick(ctx, member: discord.Member, *, Reason=None):
    await member.kick(reason=Reason)
    await ctx.send('[+] Noah has been successfully kicked')

@client.command()
async def votekick(ctx):
    global vote_started
    if not vote_started:
        vote_started = True
        # await ctx.channel.send('[+] A votekick has started')
        users_voted.append(ctx.author.id)
    else: # checks to see if user has already voted
        for user in users_voted:
            if not ctx.author.id == user:
                users_voted.append(ctx.author.id)
            else:
                await ctx.send('Error: You have already voted.')
    if len(users_voted) == 1:
        # here is where I want to call kick function

如何在votekick命令中调用kick命令? 提前谢谢


Tags: sendidifawait投票usersauthorhas