For constants $a,b$ you have
$$\sum_{i=1}^n ai+b = a \sum_{i=1}^n i + b \sum_{i=1}^n 1 = \frac{a n(n+1)}{2} + bn.$$
You can set this equal to your given number and solve for $n$; if you get an integer then your given number was whatever-gonal.
I'm not sure if this _fully_ answers your question, since I'm not that closely familiar with the -gonal numbers.