I was considering this Q&A: What is the highest possible AC?
I was curious about whether any attack roll could ever get high enough to hit such an AC (short of scoring a critical hit, which ignores AC), and that got me thinking: How high can the bonus to an attack roll get?
I'm not interested in the amount of damage done, just the static bonuses or additional dice rolls that can be added to the attack roll, hence I'm also not interested in the actual number rolled on the d20 attack roll, but if it matters, assume it's not a critical hit (and no, using Portent doesn't count as making it static; I want to exclude the d20 attack roll entirely). The bonus can be temporary or situational, hence buff spells are allowed.
Any magic items, help from friends, feats and Epic Boons, official races/classes/subclasses are allowed, but UA is not allowed, and nor is anything involving any kind of polymorph/wild shape. The "help from friends" is also subject to these restrictions, so no polymorphing or monstrous allies, only normal PCs with official races/classes/subclasses/spells, so examples of such help (which was provided to me by comments) would include things like Bardic Inspiration, bless, Guided Strike, War God's Blessing, etc.
Also assume that the maximum ability score range is 20, with the exception of Barbarians going up to 24 in STR and CON at level 20 (in other words, no Manuals/Tomes to get an ability score to 30, and no other magic items that increase your maximum such as Ioun Stones or Deck of Many Things, but class features that do the same are OK). We can also assume rolling ability scores with lucky rolls so we can have almost any ability score at 20. Also note that Ioun Stones that increase other things are fine, just not ability scores.
Effects with the same name should only be used once each, I don't want things stacking if they are the same feature/spell/etc, only different features/spells/etc. We can also assume convenient luck on any other features, such as happening to roll just below what we need on the attack to miss (if we assume a ridiculous AC from that linked question), thus activating a Hobgoblin's "Saving Face" racial feature, or rolling whatever we need from the Wild Magic Surge table.
The best I can think of off the top of my head is a level 20 Ranger (so proficiency bonus of +6) with 20 DEX, the Archery Fighting Style (+2), and is shooting their +3 Longbow at one of their favoured enemies, thus adding their WIS (also 20) to the attack roll, so that's 6 + 5 + 5 + 3 + 2 = +21 bonus (this is excluding buffs, since I didn't think of any at the time I originally wrote my first attempt).
Can we do better than that within the restrictions I've specified above?