python - discord.py:如何获取用户名的首字母?

标签 python string discord.py

我想制作一个“票务系统”,并希望它创建的 channel 具有用户首字母的名称。所以,我已经有了这个:

@client.event
async def on_raw_reaction_add(reaction):
ticket = await guildbtv.create_text_channel(name=f'ticket', overwrites=overwrites, category=supportcat,
                                                    position=None, topic='Hier kannst du dein Anliegen äussern!',
                                           reason='Ticket')

最佳答案

您可以使用client.get_user(ID).display_name获取用户名

获取 react 的公会用户昵称首字母:

@client.event
async def on_reaction_add(reaction, user):
    first_letter = user.display_name[0]

获取用户用户名首字母:

@client.event
async def on_reaction_add(reaction, user):
    first_letter = client.get_user(user.id).display_name[0]

关于python - discord.py:如何获取用户名的首字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62102752/

相关文章:

python - 如果另一个文件中存在单词,则从文件中删除单词

python - pygame中 "x"和 "y"中的独立 Sprite 运动

javascript - 如何防止字符串值在转换为数字值时四舍五入?

string - 无法在字符串 : "cannot use <xxx> (type <yyy>) as type string in map index" 的映射中使用基础类型的字符串

java - 拆分字符串方法的奇怪行为

python - Discord.py - 使用特定消息回复 DM

python - 如果文件已经存在,为什么我的机器人不替换文件?

javascript - Node.js 与 Python 中的剩余部分

Python(Discord 机器人): Passing your argument to a function

python - 根据子列表中的元素对列表进行排序