Discord accounts have hidden (until someone uses a bunch of hacking tools known as "dev tools") IDs which uniquely identify an account and never change. The username#1234 stuff is pure fluff. The per-server thing is also just an alias on the server, it still shows the foo#1234 name if you click on a profile.