【问题标题】:Discord Python Rewrite - Slice Display NameDiscord Python 重写 - 切片显示名称
【发布时间】:2020-10-02 23:41:05
【问题描述】:

我制作了一个有效的 AFK 代码,但如果用户发送消息,我需要它来分割(删除)“[AFK]”。代码是:

@client.command()
async def afk(ctx, *, message="Dind't specify a message."):
    global afk_dict
    if ctx.author in afk_dict:
        afkdict.pop(ctx.author)
        await ctx.send('Welcome back! You are no longer afk.')
        await ctx.author.edit(nick=ctx.author.display_name(slice[-6]))

    else:
        afk_dict[ctx.author] = message
        await ctx.author.edit(nick=f'[AFK] {ctx.author.display_name}')
        await ctx.send(f"{ctx.author.mention}, You're now AFK.")

我没有错误。我只需要await ctx.author.edit(nick=ctx.author.display_name(slice[-6])) 就能工作,我会很开心。

【问题讨论】:

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


    【解决方案1】:

    您需要有一个on_message 事件。这样的事情应该可以工作。

    @client.event
    async def on_message(message):
        if message.author in afk_dict.keys():
            afk_dict.pop(message.author.id, None)
            nick = message.author.display_name.split('[AFK]')[1].strip()
            await message.author.edit(nick=nick)
    

    我还建议您存储用户 ID 而不是用户名。 为此,您只需使用member.id 而不是member

    【讨论】:

    • 我的意思是,它有帮助,但我需要它来删除用户昵称上的“[AFK]”,因此它将是“nick”而不是“[AFK] nick”
    • 那仍然不做任何事情;-;
    猜你喜欢
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2018-10-16
    • 2013-07-18
    • 2019-07-05
    • 2021-11-26
    • 2021-01-02
    相关资源
    最近更新 更多