【问题标题】:How to change a discord nickname to whatever the user writes using a bot discord.py如何将不和谐昵称更改为用户使用机器人 discord.py 编写的任何内容
【发布时间】:2021-04-04 18:14:57
【问题描述】:
if message.content.startswith(f'Imagine having a name as dumb as {#name}'):
Nick = (#message author)
#change nickname of Nick to {#name}
await message.channel.send('Ikr')

我该怎么做?

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    只需使用一个简单的正则表达式

    import re
    
    @bot.event
    async def on_message(message):
        content = message.content.lower() # The actual content of the message in lowercase
        pattern = "imagine having a name as dumb as (.{0,32})" # Max length for nicks is 32 characters 
       
        if (nick := re.findall(pattern, content)): # Walrus operator, need python 3.8+
            await message.author.edit(nick=nick[0]) # Editing the actual nick
    

    【讨论】:

    • 文件“main.py”,第 75 行 if (nick := re.findall(pattern, content): ^ SyntaxError: invalid syntax 我该如何解决这个错误?
    • 哦,是的,对不起。我忘了一个右括号
    • 哦,没有错误了,但是还是不行
    • 它对我来说就像一个魅力,你一定做错了什么
    • 嗯,也许吧?我到底做了什么?
    猜你喜欢
    • 2021-03-10
    • 1970-01-01
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 2021-03-20
    • 2021-05-24
    • 2021-10-30
    相关资源
    最近更新 更多