Q: How to extract the id of this string? For other Strings it works fine, but however getting the number isn't possible. Any suggestions?
text = "<:Valorant:946399790739099688><@&945697242994602054>"
start = text.find("<@&") + len("<@&")
end = text.find(">")
print(text[start:end])


A: You could use a regex search to extract the first number
>>> import re
>>> text = "<:Valorant:946399790739099688><@&945697242994602054>"
>>> m = re.search(':(\d+)', text)
>>> m.group(1)
'946399790739099688'

if the id is the second number then instead you could use
>>> m = re.search('@&(\d+)', text)
>>> m.group(1)
'945697242994602054'


A: If all your strings are of the form :
"<:Valorant:number1><@&number2>"

you can retrieve the number using the following snippet:
s = "<:Valorant:946399790739099688><@&945697242994602054>"
number1, number2 = map(int,s[11:-1].split("><@&"))
number1, number2
>>>> (946399790739099688, 945697242994602054)


A: I use the split to pull out things if the format is always the same like this:
text = "<:Valorant:946399790739099688><@&945697242994602054>"
id = text.split("><@&")[1].split(">")[0]
print(id)


A: Mixing split and re is also a decent option, and quite powerful when things get more complex. Just adding an option, lots of good options already provided. :)
import re
text = "<:Valorant:946399790739099688><@&945697242994602054>"
o = re.split(r'[:>]|<@&', text)
print(o[1], o[2], o[4])

('Valorant', '946399790739099688', '945697242994602054')

