使用此命令时,如何将某人的昵称更改为[AFK],以及当他们返回时如何将其更改为正常昵称?

2024-06-01 07:11:28 发布

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

所以我想做的是,当成员使用这个afk命令时,它会在他们的昵称中添加[afk],当他们回来时,它会更改为og用户名

afkdict = {}
@client.command(name = "afk", brief = "Away From Keyboard",
                description = "I'll give you the afk status and if someone pings you before you come back, I'll tell "
                              "them that you are not available. You can add your own afk message!")
async def afk(ctx, message = "Gatau ngapain"):
    global afkdict

    if ctx.message.author in afkdict:
        afkdict.pop(ctx.message.author)
        await ctx.send('Welkom bek :-)')

    else:
        afkdict[ctx.message.author] = message
        await ctx.send("Siap bang jago")


@client.event
async def on_message(message):
    global afkdict

    for member in message.mentions:  
        if member != message.author:  
            if member in afkdict:  
                afkmsg = afkdict[member]  
                await message.channel.send(f"{member}lagi afk. {afkmsg}")
    await client.process_commands(message)


Tags: inclientyousendmessageasyncifdef
1条回答
网友
1楼 · 发布于 2024-06-01 07:11:28

您只需要使用member.edit(nick=nickname)。因此,在您的例子中是await ctx.author.edit(nick="[AFK]"),删除昵称await ctx.author.edit(nick="")

所以完整的命令应该是这样的

@client.command(name = "afk", brief = "Away From Keyboard",
                description = "I'll give you the afk status and if someone pings you before you come back, I'll tell "
                              "them that you are not available. You can add your own afk message!")
async def afk(ctx, message = "Gatau ngapain"):
    global afkdict

    if ctx.message.author in afkdict:
        afkdict.pop(ctx.message.author)
        await ctx.author.edit(nick="")
        await ctx.send('Welkom bek :-)')

    else:
        afkdict[ctx.message.author] = message
        await ctx.author.edit(nick="[AFK]")
        await ctx.send("Siap bang jago")

相关问题 更多 >