Skip to content

Commit e0d7c46

Browse files
Merge pull request #182 from python-discord/verify-webhook-user-exists
Check If User Exists Before Sending Webhook
2 parents 1a56c39 + 8487592 commit e0d7c46

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

backend/routes/forms/submit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import binascii
77
import datetime
88
import hashlib
9+
import typing
910
import uuid
1011
from typing import Any, Optional
1112

@@ -295,7 +296,7 @@ async def submit(self, request: Request) -> JSONResponse:
295296
async def send_submission_webhook(
296297
form: Form,
297298
response: FormResponse,
298-
request_user: User
299+
request_user: typing.Optional[User]
299300
) -> None:
300301
"""Helper to send a submission message to a discord webhook."""
301302
# Stop if webhook is not available
@@ -305,9 +306,7 @@ async def send_submission_webhook(
305306
try:
306307
mention = request_user.discord_mention
307308
except AttributeError:
308-
mention = "User"
309-
310-
user = response.user
309+
mention = "A user"
311310

312311
# Build Embed
313312
embed = {
@@ -319,7 +318,8 @@ async def send_submission_webhook(
319318
}
320319

321320
# Add author to embed
322-
if request_user.is_authenticated:
321+
if request_user and request_user.is_authenticated:
322+
user = response.user
323323
embed["author"] = {"name": request_user.display_name}
324324

325325
if user and user.avatar:

0 commit comments

Comments
 (0)