kaogeek / kaogeek-discord-bot

Discord bot for KaoGeek, built with TypeScript
MIT License
197 stars 59 forks source link

DiscordJS Framework - NestJS Discord #16

Open saenyakorn opened 1 year ago

saenyakorn commented 1 year ago

I would like to introduce frameworks for implementing Discord bot that is discord-nestjs. It allows us to implement the bot based on NestJS framework which provides greats decorators and separations of layers of logics. We can also implement REST api in it if we want.

saenyakorn commented 1 year ago

The another option is https://discordx.js.org/ which has many useful decorators.

Gusb3ll commented 1 year ago

Oh yes, I've been looking into discord-nest too. Might consider moving to use the framework kubb 👍

cc @SaltyAom @Leomotors

saenyakorn commented 1 year ago

I could setup the framework in an hour if you all agreed

dtinth commented 1 year ago

ขอบคุณที่เสนอแนวทางครับ เห็นด้วยว่าถ้ามี structure ดีๆ จะทำให้ต่อยอดได้ง่ายขึ้น

ความเห็นส่วนตัว — เคยใช้ Nest.js มาในปี 2020 ถึง 2022 แล้วส่วนตัวไม่ค่อยชอบเลยครับ เพราะว่า:

โดยรวมรู้สึกว่า JavaScript/TypeScript ecosystem มันพัฒนาจากปี 2020 มาค่อนข้างไกล แต่ Nest.js กลับไม่พัฒนาตาม ถ้าใช้ Nest.js ก็มีโอกาสที่ทำให้ติดแหง็กกับ ecosystem ยุค 2020 หรือไม่ก็ต้องไปใช้พวก 3rd party package ที่ไม่ได้ first-class support โดยทีม Nest และอาจจะพังเมื่อไหร่ก็ได้ จึงไม่ค่อยสนับสนุนเท่าไหร่ครับ ;-;

อีกตัวที่พูดถึงคือ discordx ซึ่งใช้ decorators syntax เหมือนกัน ปัญหาของ decorators syntax คือมันยังไม่เป็น standard ทำให้พวก build tooling เช่น esbuild ไม่ซัพพอร์ตครับ[^esbuild-tsc] มองว่ามีวิธีอื่นๆ ที่จะทำให้โค้ดเป็นระเบียบโดยไม่ต้องใช้ decorators (ดูตัวอย่างได้จากพวก meta-framework เช่น Next.js, Remix, Astro)

p.s. ความเข้าใจของผมอาจจะคลาดเคลื่อนนะครับ ถ้าผิดตรงไหนแย้งได้ผมจะได้เรียนรู้ด้วย

[^esbuild-tsc]: ยกเว้นว่าจะใช้ esbuild-plugin-tsc ซึ่งใช้ tsc ในการคอมไพล์ อาจจะทำให้คอมไพล์ช้า และ esbuild-kit ไม่ซัพพอร์ตการโหลดปลั๊กอินเพิ่ม

badgooooor commented 1 year ago

The another option is https://discordx.js.org/ which has many useful decorators.

Just have a quick look in this package. I don't see any test script in this one, so I'm not quite sure if we could know if there is any breaking changes that will affect this project in the future e.g. changes from Discord API itself or changes from this library 🥺.

BTW, I agree about having structure for this project which I guess it would come along after couple of features are implemented since code always evolved.

mildronize commented 1 year ago

@dtinth สอบถามหน่อยครับ ถ้าไม่ใช่ Nest.js มี Alternative ที่น่าสนใจตัวอื่นๆ มั้ยครับ โดยส่วนตัวแอบไม่ชอบ Nest.js หลายอย่างเหมือนกัน

saenyakorn commented 1 year ago

ขอบคุณคุณ @dtinth ด้วยนะครับสำหรับข้อมูลและ insights

โดยรวมเห็นด้วยเรื่องที่ NestJS อาจจะทำให้เราติดแหงกอยู่กับ syntax เก่า ๆ แต่ส่วนตัวคิดว่าตอนนี้สิ่งที่สำคัญคือการหา Framework เพื่อสร้าง standard ในการเขียน Discord bot ให้มีระเบียบก่อน feature ที่หลาย ๆ ท่านเสนอมาจะได้เกิดขึ้นจริง ๆ ได้เร็ว ๆ ครับ ถ้าวันหนี่งเราเจอ Framework / library ก็อาจจะต้องมาคุยกันอีกทีว่าจะย้ายหรือเปล่า (แต่ถ้าเรามี test ที่นัดกุมพอ เรื่องการ migrate ก็อาจจะไม่ได้น่ากลัวขนาดนั้น (?))

หรือถ้าทุกคนมี tool ตัวอื่นก็แนะนำมาได้เลยนะครับ :)

dtinth commented 1 year ago

@mildronize @saenyakorn ตอบสองท่านเลยครับ

เท่าที่ผมดูในยุค modern JavaScript ไม่ค่อยเห็น pure backend framework แล้ว ผมเห็นด้วย แต่เหตุผลสำหรับผมต่างกันครับ:

Disclaimer: เรื่อง Nest.js อย่าเชื่อความเห็นผมมาก ผมคิดว่าผมน่าจะ bias มากๆ เพราะผมหัวเสียกับมันมาพอสมควรครับ ผมเคยเปิด Issue เรื่อง ESM ตั้งแต่ปี 2021 มาปี 2023 แล้วก็ยังไม่มีอัพเดตอะไรเลย ผมเลยเลิกหวังกับคำว่า “ถ้าวันหนึ่ง” กับ Nest.js แล้วครับบ 😂

วันคุยกับ @heypoom ที่เป็น VP of Engineering เขาบอกว่า หลายๆ คนจะชอบ Nest.js ถ้าในทีมไม่มีคนที่มาคอยช่วย Evolve architecture ก็ให้ Nest.js มาทำหน้าที่เป็น Architect ให้แทน ถึง dev Node.js หลายๆ คนอาจจะไม่ชอบ แต่อย่างน้่อยก็ดูมีทิศทาง แต่เท่าที่สังเกตจากคนที่มา Contribute มีหลายคนที่มี Sense of architecture มาช่วยปรับ Architecture อยู่เรื่อยๆ เรื่องนี้ผมเลยหายห่วงครับ ตัวอย่าง PR ที่เข้ามาก็เช่น

เลยอยากเชียร์ให้ลองไปแบบไม่ต้องใช่้ Framework ไปก่อนครับ แล้วดูว่ามันมีปัญหาเรื่อง Architecture เยอะไหม

ผมเคย Deal กับโค้ดเบส Node.js ที่เละๆ มาเหมือนกันครับบ ซึ่งผม agree ว่าเทียบกับ maintain codebase เละๆ แบบนั้น สู้ maintain Nest.js codebase ดีกว่า 55555

ส่วนตัวมองว่าถ้า codebase เริ่มหลงทาง ก็น่าจะ migrate ไป Nest.js ได้นะครับ ส่วนตัวไม่ติดอะไร คิดว่า dev หลายๆ คนก็น่าจะอยู่กับมันได้เช่นกัน (แค่ส่วนตัวความสนุกของการเขียนโค้ดมันจะลดลงไปหน่อย)

saenyakorn commented 1 year ago

อันนี้แค่ FYI เฉย ๆ นะครับ อันนี้เป็น discord bot ที่ผมเขียนไว้เมื่อนานมาแล้ว ด้วย discord-nestjs ชื่อ paradis-bot เผื่อเอาไว้เป็นข้อมูลประกอบการตัดสินใจของหลาย ๆ คน ตัวอย่าง command เช่น ping command

ส่วนเหตุผลที่คุณ @dtinth ยกมาอันนี้อาจจะเห็นต่างนิดนึงเรื่องการใช้ Full stack framework เช่น NextJS, หรือ Remix มาใช้เฉพาะส่วน backend อย่างเดียว ส่วนตัวรู้สึกว่าเหมือนเราหยิบของที่ทรงพลังมากแต่ใช้งานมันนิดเดียวทำให้รู้สึกว่าเหมือนใช้งานมันได้ไม่เต็มที่เท่าไร (ซึ่งอันนี้ผมอาจจะ bias เองก็ได้ lol)

ถ้าอย่างงั้นเราไป way maintain architecture เองไปก่อนแล้วถ้า codebase มีปัญหายังไง อาจจะค่อยหยิบเรื่องนี้มาคุยกันอีกทีละกันนะครับ

หรือ dev ท่านอื่น ๆ มีความเห็นว่าอย่างไรบ้างครับ?

dtinth commented 1 year ago

@saenyakorn ดีเลยครับ มีตัวอย่างให้ reference และศึกษาเยอะๆ ขอบคุณที่แชร์ครับ