Hello I'm working with discord.py and have minimal coding experience.
in my server user names are formatted like so Bruce[12345].
I'd like to be able to pull out the numbers on either ctx.author.display_name OR on user.mention and then add those numbers elsewhere.
ie on entering command !playerid it would pull out '12345' on entering command !playerid @johndoe[67890] it would pull out '67890'
i thought this would do it but i get an unhashable error.
@bot.command() async def playerid(ctx, *, user: discord.Member = None): """get playerid"""
if user:
playerid = user.mention
if int in {playerid}
int = num
await ctx.send(f"{num}")
await ctx.message.delete()
else:
selfid = (ctx.author.display_name)
if int in {selfid}
int = selfnum
await ctx.send(f"{selfnum}")
await ctx.message.delete()
any advice?
You could do this
import re
text = 'Bruce[12345]'
m = re.findall('\[[^][]*]', text)
print(m)
['[12345]']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.