If a warlock attacks with a weapon as their action, can they use Eldritch blast as a bonus action in the same round?
Bonus actions can be taken at any time unless their timing is specified
The player gets to choose what order their actions are taken in unless the timing of those actions is specified. Bonus actions are no exception to this.
The rule you cite applies only to casting multiple spells on a turn. Since a weapon attack is an Attack action, this situation is not relevant to it.
From the Player's Handbook:
You choose when to take a bonus action during your turn unless the bonus action's timing is specified.
Also supported by Jeremy Crawford:
If a bonus action's rule tells you when you can take the action, that's when you can take it. If the rule doesn't tell you when you can take it, you choose when you take it on your turn. See the "Bonus Actions" section (PH, 189) for more information. #DnD
Do note that eldritch blast has a casting time of 1 action. You will need some way to modify that casting time (such as the quicken spell metamagic) to cast it as a bonus action. As a further note, also remember that you cannot take a bonus action unless some feature or ability allows you to.
Because of the attack action already taken, you can cast eldritch blast as a bonus action ONLY if you have a way to make eldritch blast's casting time a bonus action. It's normal casting time is one action.
Though we don't have more details on your character, and could use them, what you're quoting is the rules on bonus action spells. If you cast a spell with a bonus action as its casting time, then you can't cast another spell during the same turn except for cantrips.
Since you attacked with a weapon first, you need a way to make eldritch blast have a casting time of a bonus action - for example with the quicken metamagic if your character has levels in the sorcerer class.
Since you attacked with a weapon, you're limited to spells with a casting time of a bonus action, which "right out of the box" eldritch blast isn't.
Possibly, assuming your weapon attack specifically grants you the ability to cast Eldritch Blast as a bonus action.
A weapon attack is taking the Attack action, not the Casting a Spell action. Since you have not already cast a spell in the same turn, you may use a cantrip with a casting time of one bonus action.
You can usually take your action and bonus action in any order, but if your ability to cast Eldritch Blast as a bonus action is predicated on having used a weapon attack, the weapon attack must come first.
If you do not have a feature that gives you the specifically granted ability to cast an Eldritch Blast as a bonus action, then no. Bonus actions and Actions are not interchangeable.
Yes. If you have a cantrip which you can cast as a bonus action, you may cast it after attacking.
There are only a few cantrips which have a casting time of a bonus action.
- Shillelagh - turns a club or quarterstaff into a magic weapon
- Magic Stone - creates 1 to 3 pebbles, but you make ranged attacks with them with the Attack action
- Spare the Dying (Cleric - Grave Domain) - stabilize dying creature
- Sorcerers can also spend 2 sorcery points to quicken a cantrip so that it may be cast as a bonus action (if they know the Quickened Spell metamagic).
The only attack option of these is for Sorcerers. So a Sorcerer who knows how to cast Eldritch Blast can cast it as a bonus action by spending 2 sorcery points. They can do this before or after they use their Action to attack. The other 3 spells above can also be cast before or after the Action since they do not depend on the Action. Sometimes a class feature requires a certain kind of action to be taken prior to granting you the ability to do something as a bonus action (see below).
What you are probably actually curious about is this question:
Q: How can I attack and cast a spell as an attack on the same turn?
A: Valor Bard and Eldritch Knight can do this
- At level 14, a Valor Bard may make a single weapon attack with their bonus action after they cast a Bard spell (as an action).
So the Valor Bard can attack and cast Eldritch Blast if Eldritch Blast is on their class list. I don't know how this is possible, but if you can find a way to not just learn it, but learn it as a Bard spell, then it would work. Otherwise, you'll have to settle for a different attack cantrip.
- At level 7, an Eldritch Knight may make a single weapon attack with their bonus action after they cast a cantrip (as an action).
- At level 18, an Eldritch Knight may make a single weapon attack with their bonus action after they cast a spell (as an action).
This is your best bet, since the Eldritch Knight's ability is not restricted to their cantrips from the Wizard spell list. You can pick up Eldritch Blast or other cantrips through multiclassing or a feat such as Magic Initiate or Spell Sniper. Neither of these feats put the spell on your class list though, so you'll want to have a high ability modifier that matches the class you get the cantrip from. Also look up the Wizard cantrips in SCAG if you are an EK, since they are very nice in melee.