diff --git a/404.html b/404.html index 7856a40..6667678 100644 --- a/404.html +++ b/404.html @@ -3,21 +3,21 @@ -NestCord +NestCord - - + + - - - - - - + + + + + + -
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

+
Skip to main content

Page Not Found

We could not find what you were looking for.

Please contact the owner of the site that linked you to the original URL and let them know their link is broken.

\ No newline at end of file diff --git a/CNAME b/CNAME deleted file mode 100644 index 4baedf2..0000000 --- a/CNAME +++ /dev/null @@ -1 +0,0 @@ -nestcord.globalart.dev \ No newline at end of file diff --git a/__docusaurus/debug/config/index.html b/__docusaurus/debug/config/index.html index 0acb8a5..716f0be 100644 --- a/__docusaurus/debug/config/index.html +++ b/__docusaurus/debug/config/index.html @@ -3,21 +3,21 @@ -Docusaurus debug panel +Docusaurus debug panel - - + + - - - - - - + + + + + + -

Site config

{
title:"NestCord",
tagline:"A module for creating Discord bots using NestJS, based on Discord.js",
url:"https://nestcord.globalart.dev",
baseUrl:"/nestcord/",
onBrokenLinks:"throw",
onBrokenMarkdownLinks:"warn",
favicon:"img/favicon.ico",
organizationName:"GlobalArtInc",
projectName:"nestcord",
presets:[
[
"classic",
{}
]
],
themeConfig:{
algolia:{
appId:"N5JRHSHB9C",
apiKey:"6597eb15c31c17ecd0d7eba39b7a3848",
indexName:"nestcord",
contextualSearch:true,
schedule:"every 1 day at 3:00 pm",
searchParameters:{},
searchPagePath:"search"
},
announcementBar:{
content:"⭐️ If you like NestCord, give it a star on <a target="_blank" rel="noopener noreferrer" href="https://github.com/GlobalArtInc/nestcord">GitHub</a>! ⭐️",
id:"announcement-bar",
isCloseable:true
},
metadata:[],
navbar:{
logo:{},
items:[],
hideOnScroll:false
},
colorMode:{
defaultMode:"light",
disableSwitch:false,
respectPrefersColorScheme:true
},
footer:{
copyright:"Copyright © 2003 - 2024 • Built by <a target="_blank" href="https://globalart.dev">GlobalArt Inc</a>",
style:"light",
links:[
]
},
docs:{
versionPersistence:"localStorage",
sidebar:{}
},
prism:{
additionalLanguages:[
],
theme:{},
magicComments:[
{}
]
},
tableOfContents:{
minHeadingLevel:2,
maxHeadingLevel:3
}
},
plugins:[
"docusaurus-plugin-sass",
[
"@docusaurus/plugin-pwa",
{}
]
],
baseUrlIssueBanner:true,
i18n:{
defaultLocale:"en",
path:"i18n",
locales:[
"en"
],
localeConfigs:{
}
},
onBrokenAnchors:"warn",
onDuplicateRoutes:"warn",
staticDirectories:[
"static"
],
customFields:{
},
themes:[
],
scripts:[
],
headTags:[
],
stylesheets:[
],
clientModules:[
],
titleDelimiter:"|",
noIndex:false,
markdown:{
format:"mdx",
mermaid:false,
mdx1Compat:{
comments:true,
admonitions:true,
headingIds:true
},
anchors:{
maintainCase:false
}
}
}
+

Site config

{
title:"NestCord",
tagline:"A module for creating Discord bots using NestJS, based on Discord.js",
url:"https://nestcord.globalart.dev",
baseUrl:"/",
onBrokenLinks:"throw",
onBrokenMarkdownLinks:"warn",
favicon:"img/favicon.ico",
organizationName:"GlobalArtInc",
projectName:"nestcord",
presets:[
[
"classic",
{}
]
],
themeConfig:{
algolia:{
appId:"N5JRHSHB9C",
apiKey:"6597eb15c31c17ecd0d7eba39b7a3848",
indexName:"nestcord",
contextualSearch:true,
schedule:"every 1 day at 3:00 pm",
searchParameters:{},
searchPagePath:"search"
},
announcementBar:{
content:"⭐️ If you like NestCord, give it a star on <a target="_blank" rel="noopener noreferrer" href="https://github.com/GlobalArtInc/nestcord">GitHub</a>! ⭐️",
id:"announcement-bar",
isCloseable:true
},
metadata:[],
navbar:{
logo:{},
items:[],
hideOnScroll:false
},
colorMode:{
defaultMode:"light",
disableSwitch:false,
respectPrefersColorScheme:true
},
footer:{
copyright:"Copyright © 2003 - 2024 • Built by <a target="_blank" href="https://globalart.dev">GlobalArt Inc</a>",
style:"light",
links:[
]
},
docs:{
versionPersistence:"localStorage",
sidebar:{}
},
prism:{
additionalLanguages:[
],
theme:{},
magicComments:[
{}
]
},
tableOfContents:{
minHeadingLevel:2,
maxHeadingLevel:3
}
},
plugins:[
"docusaurus-plugin-sass",
[
"@docusaurus/plugin-pwa",
{}
]
],
baseUrlIssueBanner:true,
i18n:{
defaultLocale:"en",
path:"i18n",
locales:[
"en"
],
localeConfigs:{
}
},
onBrokenAnchors:"warn",
onDuplicateRoutes:"warn",
staticDirectories:[
"static"
],
customFields:{
},
themes:[
],
scripts:[
],
headTags:[
],
stylesheets:[
],
clientModules:[
],
titleDelimiter:"|",
noIndex:false,
markdown:{
format:"mdx",
mermaid:false,
mdx1Compat:{
comments:true,
admonitions:true,
headingIds:true
},
anchors:{
maintainCase:false
}
}
}
\ No newline at end of file diff --git a/__docusaurus/debug/content/index.html b/__docusaurus/debug/content/index.html index 5cb8b63..252c056 100644 --- a/__docusaurus/debug/content/index.html +++ b/__docusaurus/debug/content/index.html @@ -3,21 +3,21 @@ -Docusaurus debug panel +Docusaurus debug panel - - + + - - - - - - + + + + + + -

Plugin content

docusaurus-plugin-content-docs

default
{
loadedVersions:[
{}
]
}
+

Plugin content

docusaurus-plugin-content-docs

default
{
loadedVersions:[
{}
]
}
\ No newline at end of file diff --git a/__docusaurus/debug/globalData/index.html b/__docusaurus/debug/globalData/index.html index 141b82a..0ed2963 100644 --- a/__docusaurus/debug/globalData/index.html +++ b/__docusaurus/debug/globalData/index.html @@ -3,21 +3,21 @@ -Docusaurus debug panel +Docusaurus debug panel - - + + - - - - - - + + + + + + -

Global data

{
docusaurus-plugin-content-docs:{
default:{
path:"/nestcord/",
versions:[
{}
],
breadcrumbs:true
}
}
}
+

Global data

{
docusaurus-plugin-content-docs:{
default:{
path:"/",
versions:[
{}
],
breadcrumbs:true
}
}
}
\ No newline at end of file diff --git a/__docusaurus/debug/index.html b/__docusaurus/debug/index.html index 8b9a156..589bfd3 100644 --- a/__docusaurus/debug/index.html +++ b/__docusaurus/debug/index.html @@ -3,21 +3,21 @@ -Docusaurus debug panel +Docusaurus debug panel - - + + - - - - - - + + + + + + -

Site config

{
title:"NestCord",
tagline:"A module for creating Discord bots using NestJS, based on Discord.js",
url:"https://nestcord.globalart.dev",
baseUrl:"/nestcord/",
onBrokenLinks:"throw",
onBrokenMarkdownLinks:"warn",
favicon:"img/favicon.ico",
organizationName:"GlobalArtInc",
projectName:"nestcord",
presets:[
[
"classic",
{}
]
],
themeConfig:{
algolia:{
appId:"N5JRHSHB9C",
apiKey:"6597eb15c31c17ecd0d7eba39b7a3848",
indexName:"nestcord",
contextualSearch:true,
schedule:"every 1 day at 3:00 pm",
searchParameters:{},
searchPagePath:"search"
},
announcementBar:{
content:"⭐️ If you like NestCord, give it a star on <a target="_blank" rel="noopener noreferrer" href="https://github.com/GlobalArtInc/nestcord">GitHub</a>! ⭐️",
id:"announcement-bar",
isCloseable:true
},
metadata:[],
navbar:{
logo:{},
items:[],
hideOnScroll:false
},
colorMode:{
defaultMode:"light",
disableSwitch:false,
respectPrefersColorScheme:true
},
footer:{
copyright:"Copyright © 2003 - 2024 • Built by <a target="_blank" href="https://globalart.dev">GlobalArt Inc</a>",
style:"light",
links:[
]
},
docs:{
versionPersistence:"localStorage",
sidebar:{}
},
prism:{
additionalLanguages:[
],
theme:{},
magicComments:[
{}
]
},
tableOfContents:{
minHeadingLevel:2,
maxHeadingLevel:3
}
},
plugins:[
"docusaurus-plugin-sass",
[
"@docusaurus/plugin-pwa",
{}
]
],
baseUrlIssueBanner:true,
i18n:{
defaultLocale:"en",
path:"i18n",
locales:[
"en"
],
localeConfigs:{
}
},
onBrokenAnchors:"warn",
onDuplicateRoutes:"warn",
staticDirectories:[
"static"
],
customFields:{
},
themes:[
],
scripts:[
],
headTags:[
],
stylesheets:[
],
clientModules:[
],
titleDelimiter:"|",
noIndex:false,
markdown:{
format:"mdx",
mermaid:false,
mdx1Compat:{
comments:true,
admonitions:true,
headingIds:true
},
anchors:{
maintainCase:false
}
}
}
+

Site config

{
title:"NestCord",
tagline:"A module for creating Discord bots using NestJS, based on Discord.js",
url:"https://nestcord.globalart.dev",
baseUrl:"/",
onBrokenLinks:"throw",
onBrokenMarkdownLinks:"warn",
favicon:"img/favicon.ico",
organizationName:"GlobalArtInc",
projectName:"nestcord",
presets:[
[
"classic",
{}
]
],
themeConfig:{
algolia:{
appId:"N5JRHSHB9C",
apiKey:"6597eb15c31c17ecd0d7eba39b7a3848",
indexName:"nestcord",
contextualSearch:true,
schedule:"every 1 day at 3:00 pm",
searchParameters:{},
searchPagePath:"search"
},
announcementBar:{
content:"⭐️ If you like NestCord, give it a star on <a target="_blank" rel="noopener noreferrer" href="https://github.com/GlobalArtInc/nestcord">GitHub</a>! ⭐️",
id:"announcement-bar",
isCloseable:true
},
metadata:[],
navbar:{
logo:{},
items:[],
hideOnScroll:false
},
colorMode:{
defaultMode:"light",
disableSwitch:false,
respectPrefersColorScheme:true
},
footer:{
copyright:"Copyright © 2003 - 2024 • Built by <a target="_blank" href="https://globalart.dev">GlobalArt Inc</a>",
style:"light",
links:[
]
},
docs:{
versionPersistence:"localStorage",
sidebar:{}
},
prism:{
additionalLanguages:[
],
theme:{},
magicComments:[
{}
]
},
tableOfContents:{
minHeadingLevel:2,
maxHeadingLevel:3
}
},
plugins:[
"docusaurus-plugin-sass",
[
"@docusaurus/plugin-pwa",
{}
]
],
baseUrlIssueBanner:true,
i18n:{
defaultLocale:"en",
path:"i18n",
locales:[
"en"
],
localeConfigs:{
}
},
onBrokenAnchors:"warn",
onDuplicateRoutes:"warn",
staticDirectories:[
"static"
],
customFields:{
},
themes:[
],
scripts:[
],
headTags:[
],
stylesheets:[
],
clientModules:[
],
titleDelimiter:"|",
noIndex:false,
markdown:{
format:"mdx",
mermaid:false,
mdx1Compat:{
comments:true,
admonitions:true,
headingIds:true
},
anchors:{
maintainCase:false
}
}
}
\ No newline at end of file diff --git a/__docusaurus/debug/metadata/index.html b/__docusaurus/debug/metadata/index.html index 79cece7..64952fd 100644 --- a/__docusaurus/debug/metadata/index.html +++ b/__docusaurus/debug/metadata/index.html @@ -3,21 +3,21 @@ -Docusaurus debug panel +Docusaurus debug panel - - + + - - - - - - + + + + + + -

Site Metadata

Docusaurus Version: 3.3.2
Site Version: 0.0.0

Plugins and themes

  • 3.3.2
    docusaurus-plugin-content-docs
    Type: package
  • 3.3.2
    docusaurus-plugin-debug
    Type: package
  • 3.3.2
    docusaurus-plugin-sitemap
    Type: package
  • 3.3.2
    docusaurus-theme-classic
    Type: package
  • 3.3.2
    docusaurus-theme-search-algolia
    Type: package
  • 0.2.5
    docusaurus-plugin-sass
    Type: package
  • 3.3.2
    docusaurus-plugin-pwa
    Type: package
+

Site Metadata

Docusaurus Version: 3.3.2
Site Version: 0.0.0

Plugins and themes

  • 3.3.2
    docusaurus-plugin-content-docs
    Type: package
  • 3.3.2
    docusaurus-plugin-debug
    Type: package
  • 3.3.2
    docusaurus-plugin-sitemap
    Type: package
  • 3.3.2
    docusaurus-theme-classic
    Type: package
  • 3.3.2
    docusaurus-theme-search-algolia
    Type: package
  • 0.2.5
    docusaurus-plugin-sass
    Type: package
  • 3.3.2
    docusaurus-plugin-pwa
    Type: package
\ No newline at end of file diff --git a/__docusaurus/debug/registry/index.html b/__docusaurus/debug/registry/index.html index 532df24..f8f174a 100644 --- a/__docusaurus/debug/registry/index.html +++ b/__docusaurus/debug/registry/index.html @@ -3,21 +3,21 @@ -Docusaurus debug panel +Docusaurus debug panel - - + + - - - - - - + + + + + + -

Registry

  • Aliased Path: @theme/DocItem
    Resolved Path: 2430
  • Aliased Path: @site/content/contributing/code-of-conduct.md
    Resolved Path: 2714
  • Aliased Path: @site/content/interactions/message-components.md
    Resolved Path: 2157
  • Aliased Path: @site/content/techniques/validation.md
    Resolved Path: 1062
  • Aliased Path: @theme/SearchPage
    Resolved Path: 228
  • Aliased Path: @theme/DebugConfig
    Resolved Path: 5585
  • Aliased Path: @site/content/techniques/async-configuration.md
    Resolved Path: 8990
  • Aliased Path: @site/content/getting-started.md
    Resolved Path: 9993
  • Aliased Path: @site/content/contributing/funding.md
    Resolved Path: 3495
  • Aliased Path: @theme/DocsRoot
    Resolved Path: 6786
  • Aliased Path: @site/content/recipes/stat-reporter.md
    Resolved Path: 765
  • Aliased Path: @theme/DebugRegistry
    Resolved Path: 6356
  • Aliased Path: @theme/DebugSiteMetadata
    Resolved Path: 2797
  • Aliased Path: @site/content/techniques/sharding.md
    Resolved Path: 1309
  • Aliased Path: @generated/docusaurus-plugin-content-docs/default/p/nestcord-31f.json
    Resolved Path: 384
  • Aliased Path: @site/content/text-commands.md
    Resolved Path: 4073
  • Aliased Path: @site/content/listeners.md
    Resolved Path: 2536
  • Aliased Path: @site/content/techniques/client-providers.md
    Resolved Path: 4829
  • Aliased Path: @generated/docusaurus-plugin-debug/default/p/nestcord-docusaurus-debug-content-b9e.json
    Resolved Path: 6987
  • Aliased Path: @theme/DebugRoutes
    Resolved Path: 8073
  • Aliased Path: @site/content/interactions/context-menus.md
    Resolved Path: 1409
  • Aliased Path: @site/content/techniques/standalone-application.md
    Resolved Path: 5489
  • Aliased Path: @site/content/contributing/contribution-guide.md
    Resolved Path: 5467
  • Aliased Path: @theme/DocVersionRoot
    Resolved Path: 559
  • Aliased Path: @site/content/interactions/slash-commands.md
    Resolved Path: 7897
  • Aliased Path: @theme/DocRoot
    Resolved Path: 9576
  • Aliased Path: @generated/docusaurus-plugin-content-docs/default/__plugin.json
    Resolved Path: 7093
  • Aliased Path: @generated/docusaurus-plugin-debug/default/__plugin.json
    Resolved Path: 7146
  • Aliased Path: @theme/DebugContent
    Resolved Path: 9204
  • Aliased Path: @site/content/recipes/pagination.md
    Resolved Path: 3117
  • Aliased Path: @generated/docusaurus-theme-search-algolia/default/__plugin.json
    Resolved Path: 936
  • Aliased Path: @site/content/interceptors/defer-interceptor.md
    Resolved Path: 788
  • Aliased Path: @site/content/recipes/localization.md
    Resolved Path: 792
  • Aliased Path: @site/content/interactions/modals.md
    Resolved Path: 6845
  • Aliased Path: @site/content/intro.md
    Resolved Path: 9451
  • Aliased Path: @theme/DebugGlobalData
    Resolved Path: 2080
  • Aliased Path: @site/content/contributing/commit-convention.md
    Resolved Path: 6813
+

Registry

  • Aliased Path: @theme/DocItem
    Resolved Path: 2430
  • Aliased Path: @site/content/contributing/code-of-conduct.md
    Resolved Path: 2714
  • Aliased Path: @site/content/interactions/message-components.md
    Resolved Path: 2157
  • Aliased Path: @site/content/techniques/validation.md
    Resolved Path: 1062
  • Aliased Path: @generated/docusaurus-plugin-debug/default/p/docusaurus-debug-content-4f8.json
    Resolved Path: 6154
  • Aliased Path: @theme/SearchPage
    Resolved Path: 228
  • Aliased Path: @theme/DebugConfig
    Resolved Path: 5585
  • Aliased Path: @site/content/techniques/async-configuration.md
    Resolved Path: 8990
  • Aliased Path: @site/content/getting-started.md
    Resolved Path: 9993
  • Aliased Path: @site/content/contributing/funding.md
    Resolved Path: 3495
  • Aliased Path: @theme/DocsRoot
    Resolved Path: 6786
  • Aliased Path: @site/content/recipes/stat-reporter.md
    Resolved Path: 765
  • Aliased Path: @generated/docusaurus-plugin-content-docs/default/p/index.json
    Resolved Path: 7691
  • Aliased Path: @theme/DebugRegistry
    Resolved Path: 6356
  • Aliased Path: @theme/DebugSiteMetadata
    Resolved Path: 2797
  • Aliased Path: @site/content/techniques/sharding.md
    Resolved Path: 1309
  • Aliased Path: @site/content/text-commands.md
    Resolved Path: 4073
  • Aliased Path: @site/content/listeners.md
    Resolved Path: 2536
  • Aliased Path: @site/content/techniques/client-providers.md
    Resolved Path: 4829
  • Aliased Path: @theme/DebugRoutes
    Resolved Path: 8073
  • Aliased Path: @site/content/interactions/context-menus.md
    Resolved Path: 1409
  • Aliased Path: @site/content/techniques/standalone-application.md
    Resolved Path: 5489
  • Aliased Path: @site/content/contributing/contribution-guide.md
    Resolved Path: 5467
  • Aliased Path: @theme/DocVersionRoot
    Resolved Path: 559
  • Aliased Path: @site/content/interactions/slash-commands.md
    Resolved Path: 7897
  • Aliased Path: @theme/DocRoot
    Resolved Path: 9576
  • Aliased Path: @generated/docusaurus-plugin-content-docs/default/__plugin.json
    Resolved Path: 7093
  • Aliased Path: @generated/docusaurus-plugin-debug/default/__plugin.json
    Resolved Path: 7146
  • Aliased Path: @theme/DebugContent
    Resolved Path: 9204
  • Aliased Path: @site/content/recipes/pagination.md
    Resolved Path: 3117
  • Aliased Path: @generated/docusaurus-theme-search-algolia/default/__plugin.json
    Resolved Path: 936
  • Aliased Path: @site/content/interceptors/defer-interceptor.md
    Resolved Path: 788
  • Aliased Path: @site/content/recipes/localization.md
    Resolved Path: 792
  • Aliased Path: @site/content/interactions/modals.md
    Resolved Path: 6845
  • Aliased Path: @site/content/intro.md
    Resolved Path: 9451
  • Aliased Path: @theme/DebugGlobalData
    Resolved Path: 2080
  • Aliased Path: @site/content/contributing/commit-convention.md
    Resolved Path: 6813
\ No newline at end of file diff --git a/__docusaurus/debug/routes/index.html b/__docusaurus/debug/routes/index.html index b5b3d07..5ebc754 100644 --- a/__docusaurus/debug/routes/index.html +++ b/__docusaurus/debug/routes/index.html @@ -3,21 +3,21 @@ -Docusaurus debug panel +Docusaurus debug panel - - + + - - - - - - + + + + + + -

Routes

  • /nestcord/__docusaurus/debug
    Is exact: true
  • /nestcord/__docusaurus/debug/config
    Is exact: true
  • /nestcord/__docusaurus/debug/content
    Is exact: true
  • /nestcord/__docusaurus/debug/globalData
    Is exact: true
  • /nestcord/__docusaurus/debug/metadata
    Is exact: true
  • /nestcord/__docusaurus/debug/registry
    Is exact: true
  • /nestcord/__docusaurus/debug/routes
    Is exact: true
  • /nestcord/search
    Is exact: true
  • /nestcord/
    Is exact: false
    Child Routes:
    [
    {}
    ]
  • *
    Is exact: false
+

Routes

  • /__docusaurus/debug
    Is exact: true
  • /__docusaurus/debug/config
    Is exact: true
  • /__docusaurus/debug/content
    Is exact: true
  • /__docusaurus/debug/globalData
    Is exact: true
  • /__docusaurus/debug/metadata
    Is exact: true
  • /__docusaurus/debug/registry
    Is exact: true
  • /__docusaurus/debug/routes
    Is exact: true
  • /search
    Is exact: true
  • /
    Is exact: false
    Child Routes:
    [
    {}
    ]
  • *
    Is exact: false
\ No newline at end of file diff --git a/assets/js/003b49f9.d174635f.js b/assets/js/003b49f9.d174635f.js deleted file mode 100644 index 8e4fe41..0000000 --- a/assets/js/003b49f9.d174635f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[506],{2714:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>s,contentTitle:()=>a,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var t=i(6070),o=i(5710);const r={id:"code-of-conduct",title:"Code of Conduct",sidebar_position:2},a="Contributor Covenant Code of Conduct",c={id:"contributing/code-of-conduct",title:"Code of Conduct",description:"Our Pledge",source:"@site/content/contributing/code-of-conduct.md",sourceDirName:"contributing",slug:"/contributing/code-of-conduct",permalink:"/nestcord/contributing/code-of-conduct",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/code-of-conduct.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"code-of-conduct",title:"Code of Conduct",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Contribution Guide",permalink:"/nestcord/contributing/contribution-guide"},next:{title:"Commit convention",permalink:"/nestcord/contributing/commit-convention"}},s={},d=[{value:"Our Pledge",id:"our-pledge",level:2},{value:"Our Standards",id:"our-standards",level:2},{value:"Our Responsibilities",id:"our-responsibilities",level:2},{value:"Scope",id:"scope",level:2},{value:"Attribution",id:"attribution",level:2}];function l(e){const n={a:"a",h1:"h1",h2:"h2",li:"li",p:"p",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h1,{id:"contributor-covenant-code-of-conduct",children:"Contributor Covenant Code of Conduct"}),"\n",(0,t.jsx)(n.h2,{id:"our-pledge",children:"Our Pledge"}),"\n",(0,t.jsx)(n.p,{children:"In the interest of fostering an open and welcoming environment, we as\ncontributors and maintainers pledge to making participation in our project and\nour community a harassment-free experience for everyone, regardless of age, body\nsize, disability, ethnicity, gender identity and expression, level of experience,\nnationality, personal appearance, race, religion, or sexual identity and\norientation."}),"\n",(0,t.jsx)(n.h2,{id:"our-standards",children:"Our Standards"}),"\n",(0,t.jsx)(n.p,{children:"Examples of behavior that contributes to creating a positive environment\ninclude:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Using welcoming and inclusive language"}),"\n",(0,t.jsx)(n.li,{children:"Being respectful of differing viewpoints and experiences"}),"\n",(0,t.jsx)(n.li,{children:"Gracefully accepting constructive criticism"}),"\n",(0,t.jsx)(n.li,{children:"Focusing on what is best for the community"}),"\n",(0,t.jsx)(n.li,{children:"Showing empathy towards other community members"}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Examples of unacceptable behavior by participants include:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"The use of sexualized language or imagery and unwelcome sexual attention or\nadvances"}),"\n",(0,t.jsx)(n.li,{children:"Trolling, insulting/derogatory comments, and personal or political attacks"}),"\n",(0,t.jsx)(n.li,{children:"Public or private harassment"}),"\n",(0,t.jsx)(n.li,{children:"Publishing others' private information, such as a physical or electronic\naddress, without explicit permission"}),"\n",(0,t.jsx)(n.li,{children:"Other conduct which could reasonably be considered inappropriate in a\nprofessional setting"}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"our-responsibilities",children:"Our Responsibilities"}),"\n",(0,t.jsx)(n.p,{children:"Project maintainers are responsible for clarifying the standards of acceptable\nbehavior and are expected to take appropriate and fair corrective action in\nresponse to any instances of unacceptable behavior."}),"\n",(0,t.jsx)(n.p,{children:"Project maintainers have the right and responsibility to remove, edit, or\nreject comments, commits, code, wiki edits, issues, and other contributions\nthat are not aligned to this Code of Conduct, or to ban temporarily or\npermanently any contributor for other behaviors that they deem inappropriate,\nthreatening, offensive, or harmful."}),"\n",(0,t.jsx)(n.h2,{id:"scope",children:"Scope"}),"\n",(0,t.jsx)(n.p,{children:"This Code of Conduct applies both within project spaces and in public spaces\nwhen an individual is representing the project or its community. Examples of\nrepresenting a project or community include using an official project e-mail\naddress, posting via an official social media account, or acting as an appointed\nrepresentative at an online or offline event. Representation of a project may be\nfurther defined and clarified by project maintainers."}),"\n",(0,t.jsx)(n.h2,{id:"attribution",children:"Attribution"}),"\n",(0,t.jsxs)(n.p,{children:["This Code of Conduct is adapted from the ",(0,t.jsx)(n.a,{href:"http://contributor-covenant.org",children:"Contributor Covenant"}),", version 1.4,\navailable at ",(0,t.jsx)(n.a,{href:"http://contributor-covenant.org/version/1/4/",children:"http://contributor-covenant.org/version/1/4"})]})]})}function u(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(l,{...e})}):l(e)}},5710:(e,n,i)=>{i.d(n,{R:()=>a,x:()=>c});var t=i(758);const o={},r=t.createContext(o);function a(e){const n=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/003b49f9.f5f9dbe0.js b/assets/js/003b49f9.f5f9dbe0.js new file mode 100644 index 0000000..419e53c --- /dev/null +++ b/assets/js/003b49f9.f5f9dbe0.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[506],{2714:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>s,contentTitle:()=>a,default:()=>u,frontMatter:()=>r,metadata:()=>c,toc:()=>d});var t=i(6070),o=i(5710);const r={id:"code-of-conduct",title:"Code of Conduct",sidebar_position:2},a="Contributor Covenant Code of Conduct",c={id:"contributing/code-of-conduct",title:"Code of Conduct",description:"Our Pledge",source:"@site/content/contributing/code-of-conduct.md",sourceDirName:"contributing",slug:"/contributing/code-of-conduct",permalink:"/contributing/code-of-conduct",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/code-of-conduct.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"code-of-conduct",title:"Code of Conduct",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Contribution Guide",permalink:"/contributing/contribution-guide"},next:{title:"Commit convention",permalink:"/contributing/commit-convention"}},s={},d=[{value:"Our Pledge",id:"our-pledge",level:2},{value:"Our Standards",id:"our-standards",level:2},{value:"Our Responsibilities",id:"our-responsibilities",level:2},{value:"Scope",id:"scope",level:2},{value:"Attribution",id:"attribution",level:2}];function l(e){const n={a:"a",h1:"h1",h2:"h2",li:"li",p:"p",ul:"ul",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h1,{id:"contributor-covenant-code-of-conduct",children:"Contributor Covenant Code of Conduct"}),"\n",(0,t.jsx)(n.h2,{id:"our-pledge",children:"Our Pledge"}),"\n",(0,t.jsx)(n.p,{children:"In the interest of fostering an open and welcoming environment, we as\ncontributors and maintainers pledge to making participation in our project and\nour community a harassment-free experience for everyone, regardless of age, body\nsize, disability, ethnicity, gender identity and expression, level of experience,\nnationality, personal appearance, race, religion, or sexual identity and\norientation."}),"\n",(0,t.jsx)(n.h2,{id:"our-standards",children:"Our Standards"}),"\n",(0,t.jsx)(n.p,{children:"Examples of behavior that contributes to creating a positive environment\ninclude:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"Using welcoming and inclusive language"}),"\n",(0,t.jsx)(n.li,{children:"Being respectful of differing viewpoints and experiences"}),"\n",(0,t.jsx)(n.li,{children:"Gracefully accepting constructive criticism"}),"\n",(0,t.jsx)(n.li,{children:"Focusing on what is best for the community"}),"\n",(0,t.jsx)(n.li,{children:"Showing empathy towards other community members"}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"Examples of unacceptable behavior by participants include:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:"The use of sexualized language or imagery and unwelcome sexual attention or\nadvances"}),"\n",(0,t.jsx)(n.li,{children:"Trolling, insulting/derogatory comments, and personal or political attacks"}),"\n",(0,t.jsx)(n.li,{children:"Public or private harassment"}),"\n",(0,t.jsx)(n.li,{children:"Publishing others' private information, such as a physical or electronic\naddress, without explicit permission"}),"\n",(0,t.jsx)(n.li,{children:"Other conduct which could reasonably be considered inappropriate in a\nprofessional setting"}),"\n"]}),"\n",(0,t.jsx)(n.h2,{id:"our-responsibilities",children:"Our Responsibilities"}),"\n",(0,t.jsx)(n.p,{children:"Project maintainers are responsible for clarifying the standards of acceptable\nbehavior and are expected to take appropriate and fair corrective action in\nresponse to any instances of unacceptable behavior."}),"\n",(0,t.jsx)(n.p,{children:"Project maintainers have the right and responsibility to remove, edit, or\nreject comments, commits, code, wiki edits, issues, and other contributions\nthat are not aligned to this Code of Conduct, or to ban temporarily or\npermanently any contributor for other behaviors that they deem inappropriate,\nthreatening, offensive, or harmful."}),"\n",(0,t.jsx)(n.h2,{id:"scope",children:"Scope"}),"\n",(0,t.jsx)(n.p,{children:"This Code of Conduct applies both within project spaces and in public spaces\nwhen an individual is representing the project or its community. Examples of\nrepresenting a project or community include using an official project e-mail\naddress, posting via an official social media account, or acting as an appointed\nrepresentative at an online or offline event. Representation of a project may be\nfurther defined and clarified by project maintainers."}),"\n",(0,t.jsx)(n.h2,{id:"attribution",children:"Attribution"}),"\n",(0,t.jsxs)(n.p,{children:["This Code of Conduct is adapted from the ",(0,t.jsx)(n.a,{href:"http://contributor-covenant.org",children:"Contributor Covenant"}),", version 1.4,\navailable at ",(0,t.jsx)(n.a,{href:"http://contributor-covenant.org/version/1/4/",children:"http://contributor-covenant.org/version/1/4"})]})]})}function u(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(l,{...e})}):l(e)}},5710:(e,n,i)=>{i.d(n,{R:()=>a,x:()=>c});var t=i(758);const o={},r=t.createContext(o);function a(e){const n=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0b6bdc6b.33d16acd.js b/assets/js/0b6bdc6b.33d16acd.js new file mode 100644 index 0000000..a2d081d --- /dev/null +++ b/assets/js/0b6bdc6b.33d16acd.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[886],{2157:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>o,default:()=>p,frontMatter:()=>c,metadata:()=>r,toc:()=>a});var l=t(6070),s=t(5710);const c={id:"message-components",title:"Message Components",sidebar_position:3},o=void 0,r={id:"interactions/message-components",title:"Message Components",description:"Message components \u2014 we'll call them \"components\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They're accessible, customizable, and easy to use.",source:"@site/content/interactions/message-components.md",sourceDirName:"interactions",slug:"/interactions/message-components",permalink:"/interactions/message-components",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/message-components.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{id:"message-components",title:"Message Components",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Context Menus",permalink:"/interactions/context-menus"},next:{title:"Modals",permalink:"/interactions/modals"}},i={},a=[{value:"Button",id:"button",level:2},{value:"Dynamic Button",id:"dynamic-button",level:3},{value:"Select Menu",id:"select-menu",level:2},{value:"String Select",id:"string-select",level:3},{value:"User Select",id:"user-select",level:3},{value:"Role Select",id:"role-select",level:3},{value:"Channel Select",id:"channel-select",level:3},{value:"Mentionable Select",id:"mentionable-select",level:3},{value:"Dynamic Select Menu",id:"dynamic-select-menu",level:3}];function d(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Message components"})," \u2014 we'll call them \"components\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They're accessible, customizable, and easy to use."]}),"\n",(0,l.jsx)(n.p,{children:"There are several different types of components; this documentation will outline the basics of this new framework and each example."}),"\n",(0,l.jsx)(n.h2,{id:"button",children:"Button"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Buttons"})," are interactive components that render on messages. They can be clicked by users, and send an ",(0,l.jsx)(n.a,{href:"https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object",children:"interaction"})," to your app when clicked."]}),"\n",(0,l.jsx)("img",{src:"/img/content/button.png",alt:"Buttons",width:"500"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",metastring:'title="app.components.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, Button, ButtonContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @Button('BUTTON')\n public onButton(@Context() [interaction]: ButtonContext) {\n return interaction.reply({ content: 'Button clicked!' });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"dynamic-button",children:"Dynamic Button"}),"\n",(0,l.jsxs)(n.p,{children:["You can create buttons with dynamic ",(0,l.jsx)(n.code,{children:"id"})," field. This is useful for passing metadata to buttons."]}),"\n",(0,l.jsxs)(n.p,{children:["Dynamic buttons uses ",(0,l.jsx)(n.a,{href:"https://www.npmjs.com/package/path-to-regexp",children:"path-to-regexp"})," format to perform regexp matching. Turn a path string such as ",(0,l.jsx)(n.code,{children:"user/:name"})," into a regular expression."]}),"\n",(0,l.jsx)(n.p,{children:"To create a Dynamic button"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new ButtonBuilder()\n .setCustomId('click/12345')\n .setLabel('LABEL')\n .setStyle(ButtonStyle.Primary)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Dynamic button"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { Context, Button, ButtonContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @Button('click/:value')\n public onButton(\n @Context() [interaction]: ButtonContext,\n @ComponentParam('value') value: string\n ) {\n return interaction.reply({ content: `Button clicked! Value: ${value}` });\n }\n}\n\n"})}),"\n",(0,l.jsx)(n.h2,{id:"select-menu",children:"Select Menu"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Select menus"})," are another interactive component that renders on messages. On desktop, clicking on a select menu opens a dropdown-style UI; on mobile, tapping a select menu opens up a half-sheet with the options."]}),"\n",(0,l.jsx)("img",{src:"/img/content/select-menu.png",alt:"Select Menu",width:"500"}),"\n",(0,l.jsx)(n.p,{children:"Discord has introduced new select menu components :"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"String Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"User Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"Role Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"Mentionable Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"Channel Select"})}),"\n"]}),"\n",(0,l.jsx)(n.h3,{id:"string-select",children:"String Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"String Select"})," is Select Menu for picking defined text options"]}),"\n",(0,l.jsx)(n.p,{children:"To create String Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new StringSelectMenuBuilder()\n .setCustomId('STRING_SELECT_MENU') // replace with your customId\n .setPlaceholder('Select your color')\n .setMaxValues(1)\n .setMinValues(1)\n .setOptions([\n { label: 'Red', value: 'Red' },\n { label: 'Blue', value: 'Blue' },\n { label: 'Yellow', value: 'Yellow' }\n ])\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a String Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { Context, StringSelect, StringSelectContext, SelectedStrings } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @StringSelect('STRING_SELECT_MENU')\n public onStringSelect(\n @Context() [interaction]: StringSelectContext,\n @SelectedStrings() selected: string[]\n ) {\n return interaction.reply({\n content: `Your selected color - ${selected.join(' ')}`\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"user-select",children:"User Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"User Select"})," are Select Menu for selecting users"]}),"\n",(0,l.jsx)(n.p,{children:"To create User Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new UserSelectMenuBuilder()\n .setCustomId('USER_SELECT_MENU')\n .setPlaceholder('Select a user')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a User Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n UserSelect,\n UserSelectContext,\n SelectedUser,\n ISelectedUser,\n SelectedMembers,\n ISelectedMembers\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @UserSelect('USER_SELECT_MENU')\n public onUserSelect(\n @Context() [interaction]: UserSelectContext,\n @SelectedUsers() users: ISelectedUsers, // Collection of users\n @SelectedMembers() members: ISelectedMembers // Collection of members\n ) {\n interaction.reply({\n content: `\n Selected users - ${users.map(user => user.username).join(',')}\\n\n Selected members - ${members.map(member => member.user?.username).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"role-select",children:"Role Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Role Select"})," are Select Menu for selecting roles"]}),"\n",(0,l.jsx)(n.p,{children:"To create Role Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new RoleSelectMenuBuilder()\n .setCustomId('ROLE_SELECT_MENU')\n .setPlaceholder('Select a role')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Role Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n RoleSelect,\n RoleSelectContext,\n SelectedRole,\n ISelectedRole,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @RoleSelect('ROLE_SELECT_MENU')\n public onRoleSelect(\n @Context() [interaction]: RoleSelectContext,\n @SelectedRoles() roles: ISelectedRoles, // Collection of roles\n ) {\n interaction.reply({\n content: `\n Selected roles - ${roles.map(role => role.id).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"channel-select",children:"Channel Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Channel Select"})," are Select Menu for selecting channels"]}),"\n",(0,l.jsx)(n.p,{children:"To create Channel Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new ChannelSelectMenuBuilder()\n .setCustomId('CHANNEL_SELECT_MENU')\n .setPlaceholder('Select a channel')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Channel Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n ChannelSelect,\n ChannelSelectContext,\n SelectedChannel,\n ISelectedChannel,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @ChannelSelect('CHANNEL_SELECT_MENU')\n public onChannelSelect(\n @Context() [interaction]: ChannelSelectContext,\n @SelectedChannels() channels: ISelectedChannels, // Collection of channels\n ) {\n interaction.reply({\n content: `\n Selected channels - ${channels.map(channel => channel.id).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"mentionable-select",children:"Mentionable Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Mentionable Select"})," are Select Menu for selecting mentionables (users and roles)"]}),"\n",(0,l.jsx)(n.p,{children:"To create Mentionable Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new MentionableSelectMenuBuilder()\n .setCustomId('MENTIONABLE_SELECT_MENU')\n .setPlaceholder('Select a user/role')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Mentionable Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n MentionableSelect,\n MentionableSelectContext,\n SelectedUsers,\n ISelectedUsers,\n SelectedMembers,\n ISelectedMembers,\n SelectedRoles,\n ISelectedRoles,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @MentionableSelect('MENTIONABLE_SELECT_MENU')\n public onMentionableSelect(\n @Context() [interaction]: MentionableSelectContext,\n @SelectedUsers() users: ISelectedUsers,\n @SelectedMembers() members: ISelectedMembers,\n @SelectedRoles() roles: ISelectedRoles\n ) {\n return interaction.reply({\n content: `\n Selected users - ${users.map(user => user.username).join(',')}\\n\n Selected members - ${members.map(member => member.user?.username).join(',')}\\n\n Selected roles - ${roles.map(role => role.name).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"dynamic-select-menu",children:"Dynamic Select Menu"}),"\n",(0,l.jsxs)(n.p,{children:["All of the Select Menu types, support Dynamic ",(0,l.jsx)(n.code,{children:"id"})," using ",(0,l.jsx)(n.a,{href:"https://www.npmjs.com/package/path-to-regexp",children:"path-to-regexp"})," format."]}),"\n",(0,l.jsx)(n.p,{children:"To create a Dynamic select menu"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new StringSelectMenuBuilder()\n .setCustomId('preferences/color')\n .setPlaceholder('Select a color')\n .setMaxValues(1)\n .setMinValues(1)\n .setOptions([\n { label: 'Red', value: 'Red' },\n { label: 'Blue', value: 'Blue' },\n { label: 'Yellow', value: 'Yellow' }\n ])\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Dynamic select menu"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { Context, StringSelect, StringSelectContext,SelectedStrings } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @StringSelect('preferences/:item')\n\tpublic onPreferenceSelect(\n\t\t@Context() [interaction]: StringSelectContext,\n\t\t@SelectedStrings() values: string[],\n\t\t@ComponentParam('item') item: string\n\t) {\n\t\treturn interaction.reply({\n\t\t\tcontent: `\n ${item} = ${values.join(',')}\\n\n `\n\t\t});\n\t}\n}\n\n"})}),"\n",(0,l.jsx)(n.p,{children:"Dynamic select menus are compatible with :"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"StringSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"UserSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"RoleSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"MentionableSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"ChannelSelect"})}),"\n"]})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(d,{...e})}):d(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>o,x:()=>r});var l=t(758);const s={},c=l.createContext(s);function o(e){const n=l.useContext(c);return l.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),l.createElement(c.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/0b6bdc6b.bf065a87.js b/assets/js/0b6bdc6b.bf065a87.js deleted file mode 100644 index 5529b2e..0000000 --- a/assets/js/0b6bdc6b.bf065a87.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[886],{2157:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>o,default:()=>p,frontMatter:()=>c,metadata:()=>r,toc:()=>a});var l=t(6070),s=t(5710);const c={id:"message-components",title:"Message Components",sidebar_position:3},o=void 0,r={id:"interactions/message-components",title:"Message Components",description:"Message components \u2014 we'll call them \"components\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They're accessible, customizable, and easy to use.",source:"@site/content/interactions/message-components.md",sourceDirName:"interactions",slug:"/interactions/message-components",permalink:"/nestcord/interactions/message-components",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/message-components.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{id:"message-components",title:"Message Components",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Context Menus",permalink:"/nestcord/interactions/context-menus"},next:{title:"Modals",permalink:"/nestcord/interactions/modals"}},i={},a=[{value:"Button",id:"button",level:2},{value:"Dynamic Button",id:"dynamic-button",level:3},{value:"Select Menu",id:"select-menu",level:2},{value:"String Select",id:"string-select",level:3},{value:"User Select",id:"user-select",level:3},{value:"Role Select",id:"role-select",level:3},{value:"Channel Select",id:"channel-select",level:3},{value:"Mentionable Select",id:"mentionable-select",level:3},{value:"Dynamic Select Menu",id:"dynamic-select-menu",level:3}];function d(e){const n={a:"a",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Message components"})," \u2014 we'll call them \"components\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They're accessible, customizable, and easy to use."]}),"\n",(0,l.jsx)(n.p,{children:"There are several different types of components; this documentation will outline the basics of this new framework and each example."}),"\n",(0,l.jsx)(n.h2,{id:"button",children:"Button"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Buttons"})," are interactive components that render on messages. They can be clicked by users, and send an ",(0,l.jsx)(n.a,{href:"https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object",children:"interaction"})," to your app when clicked."]}),"\n",(0,l.jsx)("img",{src:"/img/content/button.png",alt:"Buttons",width:"500"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",metastring:'title="app.components.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, Button, ButtonContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @Button('BUTTON')\n public onButton(@Context() [interaction]: ButtonContext) {\n return interaction.reply({ content: 'Button clicked!' });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"dynamic-button",children:"Dynamic Button"}),"\n",(0,l.jsxs)(n.p,{children:["You can create buttons with dynamic ",(0,l.jsx)(n.code,{children:"id"})," field. This is useful for passing metadata to buttons."]}),"\n",(0,l.jsxs)(n.p,{children:["Dynamic buttons uses ",(0,l.jsx)(n.a,{href:"https://www.npmjs.com/package/path-to-regexp",children:"path-to-regexp"})," format to perform regexp matching. Turn a path string such as ",(0,l.jsx)(n.code,{children:"user/:name"})," into a regular expression."]}),"\n",(0,l.jsx)(n.p,{children:"To create a Dynamic button"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new ButtonBuilder()\n .setCustomId('click/12345')\n .setLabel('LABEL')\n .setStyle(ButtonStyle.Primary)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Dynamic button"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { Context, Button, ButtonContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @Button('click/:value')\n public onButton(\n @Context() [interaction]: ButtonContext,\n @ComponentParam('value') value: string\n ) {\n return interaction.reply({ content: `Button clicked! Value: ${value}` });\n }\n}\n\n"})}),"\n",(0,l.jsx)(n.h2,{id:"select-menu",children:"Select Menu"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Select menus"})," are another interactive component that renders on messages. On desktop, clicking on a select menu opens a dropdown-style UI; on mobile, tapping a select menu opens up a half-sheet with the options."]}),"\n",(0,l.jsx)("img",{src:"/img/content/select-menu.png",alt:"Select Menu",width:"500"}),"\n",(0,l.jsx)(n.p,{children:"Discord has introduced new select menu components :"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"String Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"User Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"Role Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"Mentionable Select"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"Channel Select"})}),"\n"]}),"\n",(0,l.jsx)(n.h3,{id:"string-select",children:"String Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"String Select"})," is Select Menu for picking defined text options"]}),"\n",(0,l.jsx)(n.p,{children:"To create String Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new StringSelectMenuBuilder()\n .setCustomId('STRING_SELECT_MENU') // replace with your customId\n .setPlaceholder('Select your color')\n .setMaxValues(1)\n .setMinValues(1)\n .setOptions([\n { label: 'Red', value: 'Red' },\n { label: 'Blue', value: 'Blue' },\n { label: 'Yellow', value: 'Yellow' }\n ])\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a String Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { Context, StringSelect, StringSelectContext, SelectedStrings } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @StringSelect('STRING_SELECT_MENU')\n public onStringSelect(\n @Context() [interaction]: StringSelectContext,\n @SelectedStrings() selected: string[]\n ) {\n return interaction.reply({\n content: `Your selected color - ${selected.join(' ')}`\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"user-select",children:"User Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"User Select"})," are Select Menu for selecting users"]}),"\n",(0,l.jsx)(n.p,{children:"To create User Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new UserSelectMenuBuilder()\n .setCustomId('USER_SELECT_MENU')\n .setPlaceholder('Select a user')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a User Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n UserSelect,\n UserSelectContext,\n SelectedUser,\n ISelectedUser,\n SelectedMembers,\n ISelectedMembers\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @UserSelect('USER_SELECT_MENU')\n public onUserSelect(\n @Context() [interaction]: UserSelectContext,\n @SelectedUsers() users: ISelectedUsers, // Collection of users\n @SelectedMembers() members: ISelectedMembers // Collection of members\n ) {\n interaction.reply({\n content: `\n Selected users - ${users.map(user => user.username).join(',')}\\n\n Selected members - ${members.map(member => member.user?.username).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"role-select",children:"Role Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Role Select"})," are Select Menu for selecting roles"]}),"\n",(0,l.jsx)(n.p,{children:"To create Role Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new RoleSelectMenuBuilder()\n .setCustomId('ROLE_SELECT_MENU')\n .setPlaceholder('Select a role')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Role Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n RoleSelect,\n RoleSelectContext,\n SelectedRole,\n ISelectedRole,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @RoleSelect('ROLE_SELECT_MENU')\n public onRoleSelect(\n @Context() [interaction]: RoleSelectContext,\n @SelectedRoles() roles: ISelectedRoles, // Collection of roles\n ) {\n interaction.reply({\n content: `\n Selected roles - ${roles.map(role => role.id).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"channel-select",children:"Channel Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Channel Select"})," are Select Menu for selecting channels"]}),"\n",(0,l.jsx)(n.p,{children:"To create Channel Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new ChannelSelectMenuBuilder()\n .setCustomId('CHANNEL_SELECT_MENU')\n .setPlaceholder('Select a channel')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Channel Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n ChannelSelect,\n ChannelSelectContext,\n SelectedChannel,\n ISelectedChannel,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @ChannelSelect('CHANNEL_SELECT_MENU')\n public onChannelSelect(\n @Context() [interaction]: ChannelSelectContext,\n @SelectedChannels() channels: ISelectedChannels, // Collection of channels\n ) {\n interaction.reply({\n content: `\n Selected channels - ${channels.map(channel => channel.id).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"mentionable-select",children:"Mentionable Select"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.strong,{children:"Mentionable Select"})," are Select Menu for selecting mentionables (users and roles)"]}),"\n",(0,l.jsx)(n.p,{children:"To create Mentionable Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new MentionableSelectMenuBuilder()\n .setCustomId('MENTIONABLE_SELECT_MENU')\n .setPlaceholder('Select a user/role')\n .setMaxValues(1)\n .setMinValues(1)\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Mentionable Select:"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { \n Context,\n MentionableSelect,\n MentionableSelectContext,\n SelectedUsers,\n ISelectedUsers,\n SelectedMembers,\n ISelectedMembers,\n SelectedRoles,\n ISelectedRoles,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @MentionableSelect('MENTIONABLE_SELECT_MENU')\n public onMentionableSelect(\n @Context() [interaction]: MentionableSelectContext,\n @SelectedUsers() users: ISelectedUsers,\n @SelectedMembers() members: ISelectedMembers,\n @SelectedRoles() roles: ISelectedRoles\n ) {\n return interaction.reply({\n content: `\n Selected users - ${users.map(user => user.username).join(',')}\\n\n Selected members - ${members.map(member => member.user?.username).join(',')}\\n\n Selected roles - ${roles.map(role => role.name).join(',')}\n `\n });\n }\n}\n"})}),"\n",(0,l.jsx)(n.h3,{id:"dynamic-select-menu",children:"Dynamic Select Menu"}),"\n",(0,l.jsxs)(n.p,{children:["All of the Select Menu types, support Dynamic ",(0,l.jsx)(n.code,{children:"id"})," using ",(0,l.jsx)(n.a,{href:"https://www.npmjs.com/package/path-to-regexp",children:"path-to-regexp"})," format."]}),"\n",(0,l.jsx)(n.p,{children:"To create a Dynamic select menu"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"new StringSelectMenuBuilder()\n .setCustomId('preferences/color')\n .setPlaceholder('Select a color')\n .setMaxValues(1)\n .setMinValues(1)\n .setOptions([\n { label: 'Red', value: 'Red' },\n { label: 'Blue', value: 'Blue' },\n { label: 'Yellow', value: 'Yellow' }\n ])\n"})}),"\n",(0,l.jsx)(n.p,{children:"To receive a Dynamic select menu"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-typescript",children:"import { Injectable } from '@nestjs/common';\nimport { Context, StringSelect, StringSelectContext,SelectedStrings } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppComponents {\n @StringSelect('preferences/:item')\n\tpublic onPreferenceSelect(\n\t\t@Context() [interaction]: StringSelectContext,\n\t\t@SelectedStrings() values: string[],\n\t\t@ComponentParam('item') item: string\n\t) {\n\t\treturn interaction.reply({\n\t\t\tcontent: `\n ${item} = ${values.join(',')}\\n\n `\n\t\t});\n\t}\n}\n\n"})}),"\n",(0,l.jsx)(n.p,{children:"Dynamic select menus are compatible with :"}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"StringSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"UserSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"RoleSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"MentionableSelect"})}),"\n",(0,l.jsx)(n.li,{children:(0,l.jsx)(n.code,{children:"ChannelSelect"})}),"\n"]})]})}function p(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(d,{...e})}):d(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>o,x:()=>r});var l=t(758);const s={},c=l.createContext(s);function o(e){const n=l.useContext(c);return l.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:o(e.components),l.createElement(c.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/107a3993.4dfa31d9.js b/assets/js/107a3993.4dfa31d9.js new file mode 100644 index 0000000..f9cf33c --- /dev/null +++ b/assets/js/107a3993.4dfa31d9.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[936],{1062:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>c,toc:()=>u});var a=n(6070),r=n(5710),s=n(8060),i=n(7113);const o={id:"validation",title:"Validation",sidebar_position:0},l=void 0,c={id:"techniques/validation",title:"Validation",description:"The ValidationPipe is a built-in pipe that can be used to validate data coming from the client. It uses class-validator package under the hood. The ValidationPipe provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module.",source:"@site/content/techniques/validation.md",sourceDirName:"techniques",slug:"/techniques/validation",permalink:"/techniques/validation",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/validation.md",tags:[],version:"current",sidebarPosition:0,frontMatter:{id:"validation",title:"Validation",sidebar_position:0},sidebar:"docsSidebar",previous:{title:"Stat Reporter",permalink:"/recipes/stat-reporter"},next:{title:"Sharding",permalink:"/techniques/sharding"}},d={},u=[{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["The ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," is a built-in pipe that can be used to validate data coming from the client. It uses ",(0,a.jsx)(t.a,{href:"https://github.com/typestack/class-validator",children:"class-validator"})," package under the hood. The ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module."]}),"\n",(0,a.jsx)(t.h2,{id:"installation",children:"Installation"}),"\n",(0,a.jsxs)(s.A,{groupId:"npm2yarn",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"$ npm install class-validator class-transformer\n"})})}),(0,a.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"$ yarn add class-validator class-transformer\n"})})}),(0,a.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"$ pnpm add class-validator class-transformer\n"})})})]}),"\n",(0,a.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,a.jsxs)(t.p,{children:["Now we can add a few validation rules in our ",(0,a.jsx)(t.code,{children:"CreateUserDto"}),". We do this using decorators provided by the class-validator package, described in detail ",(0,a.jsx)(t.a,{href:"https://github.com/typestack/class-validator#validation-decorators",children:"here"}),". In this fashion, any route that uses the ",(0,a.jsx)(t.code,{children:"CreateUserDto"})," will automatically enforce these validation rules."]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-typescript",metastring:'title="src/users/dto/create-user.dto.ts"',children:"import { IsNotEmpty, IsString, IsEmail } from 'class-validator';\n\nexport class CreateUserDto {\n @StringOption({\n name: 'name',\n description: 'Your name',\n required: true\n })\n name: string;\n\n @IsEmail()\n @StringOption({\n name: 'text',\n description: 'Your email',\n required: false\n })\n email: string;\n}\n"})}),"\n",(0,a.jsxs)(t.admonition,{type:"tip",children:[(0,a.jsxs)(t.p,{children:["Also you can use ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," for transforming and validating the payload of a request."]}),(0,a.jsx)(t.p,{children:(0,a.jsx)(t.a,{href:"https://docs.nestjs.com/techniques/validation#transform-payload-objects",children:"Read more about transforming"})})]}),"\n",(0,a.jsxs)(t.p,{children:["Now, we can use the ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," in our ",(0,a.jsx)(t.code,{children:"UsersCommands"})," to enforce the validation rules we just defined."]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-typescript",metastring:'title="src/users/users.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class UsersCommands {\n @SlashCommand({\n name: 'create',\n description: 'Create a new user'\n })\n public async onCreateUser(\n @Context() [interaction]: SlashCommandContext,\n @Options(new ValidationPipe({ validateCustomDecorators: true })) createUserDto: CreateUserDto\n ) {\n return interaction.reply({ content: `User created: ${createUserDto.name}` });\n }\n}\n"})}),"\n",(0,a.jsxs)(t.p,{children:["Now, if we try to use the ",(0,a.jsx)(t.code,{children:"create"})," command without providing a name or email, we will get an error message."]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:'{"statusCode":400,"message":["email should not be empty"],"error":"Bad Request"}\n'})}),"\n",(0,a.jsx)(t.p,{children:"You can create snippet for validated options decorator:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-typescript",metastring:'title="src/decorators/validated-options.decorator.ts"',children:"import { ValidationPipe, PipeTransform } from '@nestjs/common';\n\nexport const ValidatedOptions = (...dataOrPipes: PipeTransform[] | string) => {\n return Options(...dataOrPipes, new ValidationPipe());\n};\n"})}),"\n",(0,a.jsxs)(t.admonition,{type:"tip",children:[(0,a.jsx)(t.p,{children:"You can create filters to handle and response validation errors."}),(0,a.jsx)(t.p,{children:(0,a.jsx)(t.a,{href:"https://docs.nestjs.com/exception-filters#exception-filters",children:"See Exception Filters for more information"})})]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},7113:(e,t,n)=>{n.d(t,{A:()=>i});n(758);var a=n(3526);const r={tabItem:"tabItem_A6Wz"};var s=n(6070);function i(e){let{children:t,hidden:n,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.A)(r.tabItem,i),hidden:n,children:t})}},8060:(e,t,n)=>{n.d(t,{A:()=>w});var a=n(758),r=n(3526),s=n(5394),i=n(5557),o=n(8063),l=n(5799),c=n(1836),d=n(8552);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}(n);return function(e){const t=(0,c.X)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,a.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(r.location.search);t.set(s,e),r.replace({...r.location,search:t.toString()})}),[s,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,s=p(e),[i,l]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:s}))),[c,u]=m({queryString:n,groupId:r}),[f,v]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,s]=(0,d.Dv)(n);return[r,(0,a.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:r}),b=(()=>{const e=c??f;return h({value:e,tabValues:s})?e:null})();(0,o.A)((()=>{b&&l(b)}),[b]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),v(e)}),[u,v,s]),tabValues:s}}var v=n(2253);const b={tabList:"tabList_UwLV",tabItem:"tabItem_Clxf"};var g=n(6070);function x(e){let{className:t,block:n,selectedValue:a,selectValue:i,tabValues:o}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.a_)(),d=e=>{const t=e.currentTarget,n=l.indexOf(t),r=o[n].value;r!==a&&(c(t),i(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:a===t?0:-1,"aria-selected":a===t,ref:e=>l.push(e),onKeyDown:u,onClick:d,...s,className:(0,r.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":a===t}),children:n??t},t)}))})}function j(e){let{lazy:t,children:n,selectedValue:r}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,g.jsx)(x,{...t,...e}),(0,g.jsx)(j,{...t,...e})]})}function w(e){const t=(0,v.A)();return(0,g.jsx)(y,{...e,children:u(e.children)},String(t))}},5710:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>o});var a=n(758);const r={},s=a.createContext(r);function i(e){const t=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),a.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/107a3993.5d8e13f9.js b/assets/js/107a3993.5d8e13f9.js deleted file mode 100644 index 4fe721c..0000000 --- a/assets/js/107a3993.5d8e13f9.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[936],{1062:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>c,toc:()=>u});var a=n(6070),r=n(5710),s=n(8060),i=n(7113);const o={id:"validation",title:"Validation",sidebar_position:0},l=void 0,c={id:"techniques/validation",title:"Validation",description:"The ValidationPipe is a built-in pipe that can be used to validate data coming from the client. It uses class-validator package under the hood. The ValidationPipe provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module.",source:"@site/content/techniques/validation.md",sourceDirName:"techniques",slug:"/techniques/validation",permalink:"/nestcord/techniques/validation",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/validation.md",tags:[],version:"current",sidebarPosition:0,frontMatter:{id:"validation",title:"Validation",sidebar_position:0},sidebar:"docsSidebar",previous:{title:"Stat Reporter",permalink:"/nestcord/recipes/stat-reporter"},next:{title:"Sharding",permalink:"/nestcord/techniques/sharding"}},d={},u=[{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2}];function p(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(t.p,{children:["The ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," is a built-in pipe that can be used to validate data coming from the client. It uses ",(0,a.jsx)(t.a,{href:"https://github.com/typestack/class-validator",children:"class-validator"})," package under the hood. The ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module."]}),"\n",(0,a.jsx)(t.h2,{id:"installation",children:"Installation"}),"\n",(0,a.jsxs)(s.A,{groupId:"npm2yarn",children:[(0,a.jsx)(i.A,{value:"npm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"$ npm install class-validator class-transformer\n"})})}),(0,a.jsx)(i.A,{value:"yarn",label:"Yarn",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"$ yarn add class-validator class-transformer\n"})})}),(0,a.jsx)(i.A,{value:"pnpm",label:"pnpm",children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:"$ pnpm add class-validator class-transformer\n"})})})]}),"\n",(0,a.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,a.jsxs)(t.p,{children:["Now we can add a few validation rules in our ",(0,a.jsx)(t.code,{children:"CreateUserDto"}),". We do this using decorators provided by the class-validator package, described in detail ",(0,a.jsx)(t.a,{href:"https://github.com/typestack/class-validator#validation-decorators",children:"here"}),". In this fashion, any route that uses the ",(0,a.jsx)(t.code,{children:"CreateUserDto"})," will automatically enforce these validation rules."]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-typescript",metastring:'title="src/users/dto/create-user.dto.ts"',children:"import { IsNotEmpty, IsString, IsEmail } from 'class-validator';\n\nexport class CreateUserDto {\n @StringOption({\n name: 'name',\n description: 'Your name',\n required: true\n })\n name: string;\n\n @IsEmail()\n @StringOption({\n name: 'text',\n description: 'Your email',\n required: false\n })\n email: string;\n}\n"})}),"\n",(0,a.jsxs)(t.admonition,{type:"tip",children:[(0,a.jsxs)(t.p,{children:["Also you can use ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," for transforming and validating the payload of a request."]}),(0,a.jsx)(t.p,{children:(0,a.jsx)(t.a,{href:"https://docs.nestjs.com/techniques/validation#transform-payload-objects",children:"Read more about transforming"})})]}),"\n",(0,a.jsxs)(t.p,{children:["Now, we can use the ",(0,a.jsx)(t.code,{children:"ValidationPipe"})," in our ",(0,a.jsx)(t.code,{children:"UsersCommands"})," to enforce the validation rules we just defined."]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-typescript",metastring:'title="src/users/users.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class UsersCommands {\n @SlashCommand({\n name: 'create',\n description: 'Create a new user'\n })\n public async onCreateUser(\n @Context() [interaction]: SlashCommandContext,\n @Options(new ValidationPipe({ validateCustomDecorators: true })) createUserDto: CreateUserDto\n ) {\n return interaction.reply({ content: `User created: ${createUserDto.name}` });\n }\n}\n"})}),"\n",(0,a.jsxs)(t.p,{children:["Now, if we try to use the ",(0,a.jsx)(t.code,{children:"create"})," command without providing a name or email, we will get an error message."]}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-bash",children:'{"statusCode":400,"message":["email should not be empty"],"error":"Bad Request"}\n'})}),"\n",(0,a.jsx)(t.p,{children:"You can create snippet for validated options decorator:"}),"\n",(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-typescript",metastring:'title="src/decorators/validated-options.decorator.ts"',children:"import { ValidationPipe, PipeTransform } from '@nestjs/common';\n\nexport const ValidatedOptions = (...dataOrPipes: PipeTransform[] | string) => {\n return Options(...dataOrPipes, new ValidationPipe());\n};\n"})}),"\n",(0,a.jsxs)(t.admonition,{type:"tip",children:[(0,a.jsx)(t.p,{children:"You can create filters to handle and response validation errors."}),(0,a.jsx)(t.p,{children:(0,a.jsx)(t.a,{href:"https://docs.nestjs.com/exception-filters#exception-filters",children:"See Exception Filters for more information"})})]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},7113:(e,t,n)=>{n.d(t,{A:()=>i});n(758);var a=n(3526);const r={tabItem:"tabItem_A6Wz"};var s=n(6070);function i(e){let{children:t,hidden:n,className:i}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.A)(r.tabItem,i),hidden:n,children:t})}},8060:(e,t,n)=>{n.d(t,{A:()=>w});var a=n(758),r=n(3526),s=n(5394),i=n(5557),o=n(8063),l=n(5799),c=n(1836),d=n(8552);function u(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}(n);return function(e){const t=(0,c.X)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const r=(0,i.W6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(s),(0,a.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(r.location.search);t.set(s,e),r.replace({...r.location,search:t.toString()})}),[s,r])]}function f(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,s=p(e),[i,l]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:s}))),[c,u]=m({queryString:n,groupId:r}),[f,v]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,s]=(0,d.Dv)(n);return[r,(0,a.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:r}),b=(()=>{const e=c??f;return h({value:e,tabValues:s})?e:null})();(0,o.A)((()=>{b&&l(b)}),[b]);return{selectedValue:i,selectValue:(0,a.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),v(e)}),[u,v,s]),tabValues:s}}var v=n(2253);const b={tabList:"tabList_UwLV",tabItem:"tabItem_Clxf"};var g=n(6070);function x(e){let{className:t,block:n,selectedValue:a,selectValue:i,tabValues:o}=e;const l=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.a_)(),d=e=>{const t=e.currentTarget,n=l.indexOf(t),r=o[n].value;r!==a&&(c(t),i(r))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:a===t?0:-1,"aria-selected":a===t,ref:e=>l.push(e),onKeyDown:u,onClick:d,...s,className:(0,r.A)("tabs__item",b.tabItem,s?.className,{"tabs__item--active":a===t}),children:n??t},t)}))})}function j(e){let{lazy:t,children:n,selectedValue:r}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function y(e){const t=f(e);return(0,g.jsxs)("div",{className:(0,r.A)("tabs-container",b.tabList),children:[(0,g.jsx)(x,{...t,...e}),(0,g.jsx)(j,{...t,...e})]})}function w(e){const t=(0,v.A)();return(0,g.jsx)(y,{...e,children:u(e.children)},String(t))}},5710:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>o});var a=n(758);const r={},s=a.createContext(r);function i(e){const t=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),a.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/10f80ca5.7f737360.js b/assets/js/10f80ca5.7f737360.js new file mode 100644 index 0000000..0cda053 --- /dev/null +++ b/assets/js/10f80ca5.7f737360.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[287],{6154:e=>{e.exports=JSON.parse('{"allContent":{"docusaurus-plugin-content-docs":{"default":{"loadedVersions":[{"versionName":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","path":"/","tagsPath":"/tags","editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content","editUrlLocalized":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/i18n/en/docusaurus-plugin-content-docs/current","isLast":true,"routePriority":-1,"sidebarFilePath":"/home/rozmarinus/development/nestcord/docs/sidebars.js","contentPath":"/home/rozmarinus/development/nestcord/docs/content","contentPathLocalized":"/home/rozmarinus/development/nestcord/docs/i18n/en/docusaurus-plugin-content-docs/current","docs":[{"id":"contributing/code-of-conduct","title":"Code of Conduct","description":"Our Pledge","source":"@site/content/contributing/code-of-conduct.md","sourceDirName":"contributing","slug":"/contributing/code-of-conduct","permalink":"/contributing/code-of-conduct","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/code-of-conduct.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"code-of-conduct","title":"Code of Conduct","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Contribution Guide","permalink":"/contributing/contribution-guide"},"next":{"title":"Commit convention","permalink":"/contributing/commit-convention"}},{"id":"contributing/commit-convention","title":"Commit convention","description":"Git Commit Message Convention","source":"@site/content/contributing/commit-convention.md","sourceDirName":"contributing","slug":"/contributing/commit-convention","permalink":"/contributing/commit-convention","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/commit-convention.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"commit-convention","title":"Commit convention","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Code of Conduct","permalink":"/contributing/code-of-conduct"},"next":{"title":"Funding","permalink":"/contributing/funding"}},{"id":"contributing/contribution-guide","title":"Contribution Guide","description":"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a","source":"@site/content/contributing/contribution-guide.md","sourceDirName":"contributing","slug":"/contributing/contribution-guide","permalink":"/contributing/contribution-guide","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/contribution-guide.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"contribution-guide","title":"Contribution Guide","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Client Providers","permalink":"/techniques/client-providers"},"next":{"title":"Code of Conduct","permalink":"/contributing/code-of-conduct"}},{"id":"contributing/funding","title":"Funding","description":"NestCord is an open source project with its ongoing development made possible thanks to the support by the community.","source":"@site/content/contributing/funding.md","sourceDirName":"contributing","slug":"/contributing/funding","permalink":"/contributing/funding","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/funding.md","tags":[],"version":"current","sidebarPosition":4,"frontMatter":{"id":"funding","title":"Funding","sidebar_position":4},"sidebar":"docsSidebar","previous":{"title":"Commit convention","permalink":"/contributing/commit-convention"}},{"id":"interactions/context-menus","title":"Context Menus","description":"User commands and message commands are now live! These commands appear on context menus for users and messages, with more to come in the future.","source":"@site/content/interactions/context-menus.md","sourceDirName":"interactions","slug":"/interactions/context-menus","permalink":"/interactions/context-menus","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/context-menus.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"context-menus","title":"Context Menus","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Slash Commands","permalink":"/interactions/slash-commands"},"next":{"title":"Message Components","permalink":"/interactions/message-components"}},{"id":"interactions/message-components","title":"Message Components","description":"Message components \u2014 we\'ll call them \\"components\\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They\'re accessible, customizable, and easy to use.","source":"@site/content/interactions/message-components.md","sourceDirName":"interactions","slug":"/interactions/message-components","permalink":"/interactions/message-components","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/message-components.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"message-components","title":"Message Components","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Context Menus","permalink":"/interactions/context-menus"},"next":{"title":"Modals","permalink":"/interactions/modals"}},{"id":"interactions/modals","title":"Modals","description":"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We\'ll cover how to create, show, and receive modal forms using nestcord","source":"@site/content/interactions/modals.md","sourceDirName":"interactions","slug":"/interactions/modals","permalink":"/interactions/modals","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/modals.md","tags":[],"version":"current","sidebarPosition":4,"frontMatter":{"id":"modals","title":"Modals","sidebar_position":4},"sidebar":"docsSidebar","previous":{"title":"Message Components","permalink":"/interactions/message-components"},"next":{"title":"Text Commands","permalink":"/text-commands"}},{"id":"interactions/slash-commands","title":"Slash Commands","description":"Slash Commands are the new, exciting way to build and interact with bots on Discord. With Slash Commands, all you have to do is","source":"@site/content/interactions/slash-commands.md","sourceDirName":"interactions","slug":"/interactions/slash-commands","permalink":"/interactions/slash-commands","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/slash-commands.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"slash-commands","title":"Slash Commands","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Listeners","permalink":"/listeners"},"next":{"title":"Context Menus","permalink":"/interactions/context-menus"}},{"id":"interceptors/defer-interceptor","title":"Defer command","description":"Interceptor added interaction.deferReply() to the beiginning of the code","source":"@site/content/interceptors/defer-interceptor.md","sourceDirName":"interceptors","slug":"/interceptors/defer-interceptor","permalink":"/interceptors/defer-interceptor","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interceptors/defer-interceptor.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"defer-interceptor","title":"Defer command","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Text Commands","permalink":"/text-commands"},"next":{"title":"Pagination","permalink":"/recipes/pagination"}},{"id":"intro","title":"Introduction","description":"A module for creating Discord bots using NestJS, based on Discord.js.","source":"@site/content/intro.md","sourceDirName":".","slug":"/","permalink":"/","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/intro.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"intro","slug":"/","title":"Introduction","description":"A module for creating Discord bots using NestJS, based on Discord.js.","sidebar_position":1},"sidebar":"docsSidebar","next":{"title":"Getting Started","permalink":"/start"}},{"id":"listeners","title":"Listeners","description":"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.","source":"@site/content/listeners.md","sourceDirName":".","slug":"/listeners","permalink":"/listeners","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/listeners.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"listeners","slug":"listeners","title":"Listeners","description":"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Getting Started","permalink":"/start"},"next":{"title":"Slash Commands","permalink":"/interactions/slash-commands"}},{"id":"recipes/localization","title":"Localization","description":"Is a lightweight localization module for NestCord. It allows you to easily localize your bot\'s","source":"@site/content/recipes/localization.md","sourceDirName":"recipes","slug":"/recipes/localization","permalink":"/recipes/localization","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/localization.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"localization","title":"Localization","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Pagination","permalink":"/recipes/pagination"},"next":{"title":"Stat Reporter","permalink":"/recipes/stat-reporter"}},{"id":"recipes/pagination","title":"Pagination","description":"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and","source":"@site/content/recipes/pagination.md","sourceDirName":"recipes","slug":"/recipes/pagination","permalink":"/recipes/pagination","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/pagination.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"pagination","title":"Pagination","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Defer command","permalink":"/interceptors/defer-interceptor"},"next":{"title":"Localization","permalink":"/recipes/localization"}},{"id":"recipes/stat-reporter","title":"Stat Reporter","description":"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services.","source":"@site/content/recipes/stat-reporter.md","sourceDirName":"recipes","slug":"/recipes/stat-reporter","permalink":"/recipes/stat-reporter","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/stat-reporter.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"stat-reporter","title":"Stat Reporter","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Localization","permalink":"/recipes/localization"},"next":{"title":"Validation","permalink":"/techniques/validation"}},{"id":"start","title":"Getting Started","description":"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!","source":"@site/content/getting-started.md","sourceDirName":".","slug":"/start","permalink":"/start","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/getting-started.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"start","slug":"start","title":"Getting Started","description":"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Introduction","permalink":"/"},"next":{"title":"Listeners","permalink":"/listeners"}},{"id":"techniques/async-configuration","title":"Async Configuration","description":"When you need to pass module options asynchronously instead of statically, use the .forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration.","source":"@site/content/techniques/async-configuration.md","sourceDirName":"techniques","slug":"/techniques/async-configuration","permalink":"/techniques/async-configuration","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/async-configuration.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"async-configuration","title":"Async Configuration","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Sharding","permalink":"/techniques/sharding"},"next":{"title":"Standalone application","permalink":"/techniques/standalone-application"}},{"id":"techniques/client-providers","title":"Client Providers","description":"NestCord have snippets to access the client and its properties in your application.","source":"@site/content/techniques/client-providers.md","sourceDirName":"techniques","slug":"/techniques/client-providers","permalink":"/techniques/client-providers","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/client-providers.md","tags":[],"version":"current","sidebarPosition":4,"frontMatter":{"id":"client-providers","title":"Client Providers","sidebar_position":4},"sidebar":"docsSidebar","previous":{"title":"Standalone application","permalink":"/techniques/standalone-application"},"next":{"title":"Contribution Guide","permalink":"/contributing/contribution-guide"}},{"id":"techniques/sharding","title":"Sharding","description":"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works.","source":"@site/content/techniques/sharding.md","sourceDirName":"techniques","slug":"/techniques/sharding","permalink":"/techniques/sharding","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/sharding.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"sharding","title":"Sharding","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Validation","permalink":"/techniques/validation"},"next":{"title":"Async Configuration","permalink":"/techniques/async-configuration"}},{"id":"techniques/standalone-application","title":"Standalone application","description":"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don\'t need a web server, you can remove Express.","source":"@site/content/techniques/standalone-application.md","sourceDirName":"techniques","slug":"/techniques/standalone-application","permalink":"/techniques/standalone-application","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/standalone-application.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"standalone-application","title":"Standalone application","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Async Configuration","permalink":"/techniques/async-configuration"},"next":{"title":"Client Providers","permalink":"/techniques/client-providers"}},{"id":"techniques/validation","title":"Validation","description":"The ValidationPipe is a built-in pipe that can be used to validate data coming from the client. It uses class-validator package under the hood. The ValidationPipe provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module.","source":"@site/content/techniques/validation.md","sourceDirName":"techniques","slug":"/techniques/validation","permalink":"/techniques/validation","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/validation.md","tags":[],"version":"current","sidebarPosition":0,"frontMatter":{"id":"validation","title":"Validation","sidebar_position":0},"sidebar":"docsSidebar","previous":{"title":"Stat Reporter","permalink":"/recipes/stat-reporter"},"next":{"title":"Sharding","permalink":"/techniques/sharding"}},{"id":"text-commands","title":"Text Commands","description":"Text commands are the most common type of command. They are used to send a message to the channel.","source":"@site/content/text-commands.md","sourceDirName":".","slug":"/text-commands","permalink":"/text-commands","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/text-commands.md","tags":[],"version":"current","sidebarPosition":5,"frontMatter":{"id":"text-commands","slug":"text-commands","title":"Text Commands","description":"Text commands are the most common type of command. They are used to send a message to the channel.","sidebar_position":5},"sidebar":"docsSidebar","previous":{"title":"Modals","permalink":"/interactions/modals"},"next":{"title":"Defer command","permalink":"/interceptors/defer-interceptor"}}],"drafts":[],"sidebars":{"docsSidebar":[{"type":"doc","id":"intro"},{"type":"doc","id":"start"},{"type":"doc","id":"listeners"},{"type":"category","label":"Interactions","collapsible":true,"collapsed":false,"items":[{"type":"doc","id":"interactions/slash-commands"},{"type":"doc","id":"interactions/context-menus"},{"type":"doc","id":"interactions/message-components"},{"type":"doc","id":"interactions/modals"}]},{"type":"doc","id":"text-commands"},{"type":"category","label":"Interceptors","collapsible":true,"collapsed":true,"items":[{"type":"doc","id":"interceptors/defer-interceptor"}]},{"type":"category","label":"Recipes","collapsible":true,"collapsed":true,"items":[{"type":"doc","id":"recipes/pagination"},{"type":"doc","id":"recipes/localization"},{"type":"doc","id":"recipes/stat-reporter"}]},{"type":"category","label":"Techniques","collapsible":true,"collapsed":true,"items":[{"type":"doc","id":"techniques/validation"},{"type":"doc","id":"techniques/sharding"},{"type":"doc","id":"techniques/async-configuration"},{"type":"doc","id":"techniques/standalone-application"},{"type":"doc","id":"techniques/client-providers"}]},{"type":"category","label":"Contributing","collapsible":true,"collapsed":false,"items":[{"type":"doc","id":"contributing/contribution-guide"},{"type":"doc","id":"contributing/code-of-conduct"},{"type":"doc","id":"contributing/commit-convention"},{"type":"doc","id":"contributing/funding"}]}]}}]}},"docusaurus-plugin-debug":{},"docusaurus-plugin-sitemap":{},"docusaurus-theme-classic":{},"docusaurus-theme-search-algolia":{},"docusaurus-plugin-sass":{},"docusaurus-plugin-pwa":{},"docusaurus-bootstrap-plugin":{},"docusaurus-mdx-fallback-plugin":{}}}')}}]); \ No newline at end of file diff --git a/assets/js/393eff57.9c5335c4.js b/assets/js/393eff57.9c5335c4.js new file mode 100644 index 0000000..d12b31d --- /dev/null +++ b/assets/js/393eff57.9c5335c4.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[531],{8990:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>u,frontMatter:()=>i,metadata:()=>c,toc:()=>a});var o=t(6070),s=t(5710);const i={id:"async-configuration",title:"Async Configuration",sidebar_position:2},r=void 0,c={id:"techniques/async-configuration",title:"Async Configuration",description:"When you need to pass module options asynchronously instead of statically, use the .forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration.",source:"@site/content/techniques/async-configuration.md",sourceDirName:"techniques",slug:"/techniques/async-configuration",permalink:"/techniques/async-configuration",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/async-configuration.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"async-configuration",title:"Async Configuration",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Sharding",permalink:"/techniques/sharding"},next:{title:"Standalone application",permalink:"/techniques/standalone-application"}},d={},a=[];function l(e){const n={a:"a",code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["When you need to pass module options asynchronously instead of statically, use the ",(0,o.jsx)(n.code,{children:".forRootAsync()"})," method. As with most dynamic modules, Nest provides several techniques to deal with async configuration."]}),"\n",(0,o.jsx)(n.p,{children:"One technique is to use a factory function:"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRootAsync({\n useFactory: () => ({\n token: 'DISCORD_BOT_TOKEN',\n intents: [\n IntentsBitField.Guilds,\n IntentsBitField.GuildMessages,\n IntentsBitField.DirectMessages\n ]\n })\n })\n ]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Like other ",(0,o.jsx)(n.a,{href:"https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory",children:"factory providers"}),", our factory function can be async and can inject dependencies through inject."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRootAsync({\n imports: [ConfigModule.forFeature(nestcordModuleConfig)],\n useFactory: async (configService: ConfigService) => ({\n token: configService.get('DISCORD_BOT_TOKEN'),\n intents: [\n IntentsBitField.Guilds,\n IntentsBitField.GuildMessages,\n IntentsBitField.DirectMessages\n ]\n }),\n inject: [ConfigService]\n })\n ]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsx)(n.p,{children:"Alternatively, you can configure the NestCordModule using a class instead of a factory, as shown below:"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRootAsync({\n useClass: NestCordConfigService\n })\n ]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["The construction above instantiates ",(0,o.jsx)(n.code,{children:"NestCordConfigService"})," inside ",(0,o.jsx)(n.code,{children:"NestCordModule"}),", using it to create the required options object. Note that in this example, the ",(0,o.jsx)(n.code,{children:"NestCordConfigService"})," has to implement the ",(0,o.jsx)(n.code,{children:"NestCordOptionsFactory"})," interface, as shown below. The ",(0,o.jsx)(n.code,{children:"NestCordModule"})," will call the ",(0,o.jsx)(n.code,{children:".createNestCordOptions()"})," method on the instantiated object of the supplied class."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/discord-config.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { NestCordOptionsFactory, NestCordModuleOptions } from '@globalart/nestcord';\nimport { IntentsBitField } from 'discord.js';\n\n@Injectable()\nclass NestCordConfigService {\n createNestCordOptions(): NestCordModuleOptions {\n return {\n token: 'DISCORD_BOT_TOKEN',\n intents: [\n IntentsBitField.Guilds,\n IntentsBitField.GuildMessages,\n IntentsBitField.DirectMessages\n ]\n };\n }\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["If you want to reuse an existing options provider instead of creating a private copy inside the ",(0,o.jsx)(n.code,{children:"NestCordModule"}),", use the ",(0,o.jsx)(n.code,{children:"useExisting"})," syntax."]})]})}function u(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var o=t(758);const s={},i=o.createContext(s);function r(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/393eff57.ddbcaf15.js b/assets/js/393eff57.ddbcaf15.js deleted file mode 100644 index 5cf6815..0000000 --- a/assets/js/393eff57.ddbcaf15.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[531],{8990:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>u,frontMatter:()=>i,metadata:()=>c,toc:()=>a});var o=t(6070),s=t(5710);const i={id:"async-configuration",title:"Async Configuration",sidebar_position:2},r=void 0,c={id:"techniques/async-configuration",title:"Async Configuration",description:"When you need to pass module options asynchronously instead of statically, use the .forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration.",source:"@site/content/techniques/async-configuration.md",sourceDirName:"techniques",slug:"/techniques/async-configuration",permalink:"/nestcord/techniques/async-configuration",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/async-configuration.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"async-configuration",title:"Async Configuration",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Sharding",permalink:"/nestcord/techniques/sharding"},next:{title:"Standalone application",permalink:"/nestcord/techniques/standalone-application"}},d={},a=[];function l(e){const n={a:"a",code:"code",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:["When you need to pass module options asynchronously instead of statically, use the ",(0,o.jsx)(n.code,{children:".forRootAsync()"})," method. As with most dynamic modules, Nest provides several techniques to deal with async configuration."]}),"\n",(0,o.jsx)(n.p,{children:"One technique is to use a factory function:"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRootAsync({\n useFactory: () => ({\n token: 'DISCORD_BOT_TOKEN',\n intents: [\n IntentsBitField.Guilds,\n IntentsBitField.GuildMessages,\n IntentsBitField.DirectMessages\n ]\n })\n })\n ]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Like other ",(0,o.jsx)(n.a,{href:"https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory",children:"factory providers"}),", our factory function can be async and can inject dependencies through inject."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRootAsync({\n imports: [ConfigModule.forFeature(nestcordModuleConfig)],\n useFactory: async (configService: ConfigService) => ({\n token: configService.get('DISCORD_BOT_TOKEN'),\n intents: [\n IntentsBitField.Guilds,\n IntentsBitField.GuildMessages,\n IntentsBitField.DirectMessages\n ]\n }),\n inject: [ConfigService]\n })\n ]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsx)(n.p,{children:"Alternatively, you can configure the NestCordModule using a class instead of a factory, as shown below:"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRootAsync({\n useClass: NestCordConfigService\n })\n ]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["The construction above instantiates ",(0,o.jsx)(n.code,{children:"NestCordConfigService"})," inside ",(0,o.jsx)(n.code,{children:"NestCordModule"}),", using it to create the required options object. Note that in this example, the ",(0,o.jsx)(n.code,{children:"NestCordConfigService"})," has to implement the ",(0,o.jsx)(n.code,{children:"NestCordOptionsFactory"})," interface, as shown below. The ",(0,o.jsx)(n.code,{children:"NestCordModule"})," will call the ",(0,o.jsx)(n.code,{children:".createNestCordOptions()"})," method on the instantiated object of the supplied class."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="src/discord-config.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { NestCordOptionsFactory, NestCordModuleOptions } from '@globalart/nestcord';\nimport { IntentsBitField } from 'discord.js';\n\n@Injectable()\nclass NestCordConfigService {\n createNestCordOptions(): NestCordModuleOptions {\n return {\n token: 'DISCORD_BOT_TOKEN',\n intents: [\n IntentsBitField.Guilds,\n IntentsBitField.GuildMessages,\n IntentsBitField.DirectMessages\n ]\n };\n }\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["If you want to reuse an existing options provider instead of creating a private copy inside the ",(0,o.jsx)(n.code,{children:"NestCordModule"}),", use the ",(0,o.jsx)(n.code,{children:"useExisting"})," syntax."]})]})}function u(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>c});var o=t(758);const s={},i=o.createContext(s);function r(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5aea931f.22a1fbf4.js b/assets/js/5aea931f.22a1fbf4.js deleted file mode 100644 index 57b2769..0000000 --- a/assets/js/5aea931f.22a1fbf4.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[174],{9993:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var r=n(6070),s=n(5710),o=n(8060),a=n(7113);const i={id:"start",slug:"start",title:"Getting Started",description:"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!",sidebar_position:2},l=void 0,d={id:"start",title:"Getting Started",description:"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!",source:"@site/content/getting-started.md",sourceDirName:".",slug:"/start",permalink:"/nestcord/start",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/getting-started.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"start",slug:"start",title:"Getting Started",description:"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Introduction",permalink:"/nestcord/"},next:{title:"Listeners",permalink:"/nestcord/listeners"}},c={},u=[{value:"Module",id:"module",level:2},{value:"Slash Commands",id:"slash-commands",level:2},{value:"Running the application",id:"running-the-application",level:2}];function h(e){const t={a:"a",admonition:"admonition",br:"br",code:"code",h2:"h2",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["In this article, you'll learn about the basics of nestcord, and how it integrates with ",(0,r.jsx)(t.a,{href:"https://nestjs.com/",children:"NestJS"}),"!"]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Many of the concepts seen with nestcord are designed to be used like other components in a ",(0,r.jsx)(t.a,{href:"https://nestjs.com/",children:"NestJS"})," project.",(0,r.jsx)(t.br,{}),"\n","We recommend you to be familiar with the ",(0,r.jsx)(t.a,{href:"https://docs.nestjs.com/",children:"NestJS documentation"}),", especially its ",(0,r.jsx)(t.a,{href:"https://docs.nestjs.com/first-steps",children:"overview"})," section, before getting started."]})}),"\n",(0,r.jsxs)(t.p,{children:["The very first step is to install nestcord and its dependency, ",(0,r.jsx)(t.a,{href:"https://discord.js.org",children:(0,r.jsx)(t.code,{children:"Discord.js"})})]}),"\n",(0,r.jsxs)(o.A,{groupId:"npm2yarn",children:[(0,r.jsx)(a.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @globalart/nestcord discord.js\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["You need to install ",(0,r.jsx)(t.a,{href:"https://nodejs.org/en/",children:"Node.js"})," v16.0.0 or newer to use NestCord and Discord.js."]})}),"\n",(0,r.jsx)(t.h2,{id:"module",children:"Module"}),"\n",(0,r.jsx)(t.p,{children:"NestCord is a module like any others, and can be imported as such within your Nest application."}),"\n",(0,r.jsx)(t.admonition,{title:"NestJS modules",type:"note",children:(0,r.jsxs)(t.p,{children:["Not sure what modules are? Catch up by reading about them in ",(0,r.jsx)(t.a,{href:"https://docs.nestjs.com/modules",children:"NestJS"}),"!"]})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="discord.module.ts"',children:"import { Module } from '@nestjs/common';\nimport { AppService } from './app.service';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: process.env.DISCORD_TOKEN,\n intents: [IntentsBitField.Flags.Guilds],\n development: [process.env.DISCORD_DEVELOPMENT_GUILD_ID]\n })\n ],\n providers: [AppService]\n})\nexport class DiscordModule {}\n"})}),"\n",(0,r.jsx)(t.admonition,{type:"info",children:(0,r.jsxs)(t.p,{children:["Make sure to setup the correct ",(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.a,{href:"https://discordjs.guide/popular-topics/intents.html#privileged-intents",children:"intents"})})," required by your application!"]})}),"\n",(0,r.jsxs)(t.p,{children:["The module arguments are an extension of discord.js ",(0,r.jsx)(t.a,{href:"https://discord.js.org/#/docs/discord.js/stable/typedef/ClientOptions",children:"ClientOptions"}),", in addition to 3 nestcord options: ",(0,r.jsx)(t.code,{children:"token"}),", ",(0,r.jsx)(t.code,{children:"prefix"})," and ",(0,r.jsx)(t.code,{children:"development"}),"."]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",children:"export interface NestCordModuleOptions extends DiscordClientOptions {\n token: string;\n prefix?: string | (message: Message) => string | Promise;\n development?: Snowflake[] | false;\n skipRegistration?: boolean;\n}\n"})}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Property"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Description"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"token"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:"Your Discord token"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"prefix"})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"})," or ",(0,r.jsx)(t.code,{children:"(message: Message) => string"})]}),(0,r.jsx)(t.td,{children:"The prefix for your bot"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"development"})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"Snowflake[]"})," or ",(0,r.jsx)(t.code,{children:"false"})]}),(0,r.jsx)(t.td,{children:"The development guilds for your bot"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"skipRegistration"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:"Skip automatic registration of application commands"})]})]})]}),"\n",(0,r.jsx)(t.admonition,{title:"Warning",type:"caution",children:(0,r.jsxs)(t.p,{children:["If you have commands using the ",(0,r.jsx)(t.code,{children:"guilds"})," property, the global development argument ",(0,r.jsx)(t.strong,{children:"will not"})," overwrite it."]})}),"\n",(0,r.jsx)(t.h2,{id:"slash-commands",children:"Slash Commands"}),"\n",(0,r.jsxs)(t.p,{children:["The best way to interact with your users is to use ",(0,r.jsx)(t.a,{href:"https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ",children:"Slash commands"}),"!\nSlash commands allow you to create commands with precise arguments and choices, giving users the best experience."]}),"\n",(0,r.jsxs)(t.p,{children:["To create a command with NestCord, you can use the ",(0,r.jsx)(t.code,{children:"SlashCommand"})," decorator."]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @SlashCommand({\n name: 'ping',\n description: 'Ping command!'\n })\n public async onPing(@Context() [interaction]: SlashCommandContext) {\n return interaction.reply({ content: 'Pong!' });\n }\n}\n"})}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["When the client logs in, it will automatically register all of the commands.\nGlobal commands are cached for up to an hour, therefore to avoid the global commands cache, you should use the ",(0,r.jsx)(t.code,{children:"development"})," argument on the NestCord module. This will restrict the command to a single guild, preventing it from getting caught by the cache."]})}),"\n",(0,r.jsx)(t.h2,{id:"running-the-application",children:"Running the application"}),"\n",(0,r.jsx)(t.p,{children:"You can run the following command at your OS command prompt to start the application listening Discord API events:"}),"\n",(0,r.jsxs)(o.A,{groupId:"npm2yarn",children:[(0,r.jsx)(a.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ npm run start\n"})})}),(0,r.jsx)(a.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ yarn run start\n"})})}),(0,r.jsx)(a.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ pnpm run start\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7113:(e,t,n)=>{n.d(t,{A:()=>a});n(758);var r=n(3526);const s={tabItem:"tabItem_A6Wz"};var o=n(6070);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,a),hidden:n,children:t})}},8060:(e,t,n)=>{n.d(t,{A:()=>w});var r=n(758),s=n(3526),o=n(5394),a=n(5557),i=n(8063),l=n(5799),d=n(1836),c=n(8552);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,d.X)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const s=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,r.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(s.location.search);t.set(o,e),s.replace({...s.location,search:t.toString()})}),[o,s])]}function x(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,o=h(e),[a,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[d,u]=m({queryString:n,groupId:s}),[x,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,o]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:s}),g=(()=>{const e=d??x;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{g&&l(g)}),[g]);return{selectedValue:a,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),j(e)}),[u,j,o]),tabValues:o}}var j=n(2253);const g={tabList:"tabList_UwLV",tabItem:"tabItem_Clxf"};var b=n(6070);function f(e){let{className:t,block:n,selectedValue:r,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),s=i[n].value;s!==r&&(d(t),a(s))},u=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:u,onClick:c,...o,className:(0,s.A)("tabs__item",g.tabItem,o?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,s.A)("tabs-container",g.tabList),children:[(0,b.jsx)(f,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:u(e.children)},String(t))}},5710:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var r=n(758);const s={},o=r.createContext(s);function a(e){const t=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5aea931f.917b522f.js b/assets/js/5aea931f.917b522f.js new file mode 100644 index 0000000..b4b729b --- /dev/null +++ b/assets/js/5aea931f.917b522f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[174],{9993:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>p,frontMatter:()=>i,metadata:()=>d,toc:()=>u});var r=n(6070),s=n(5710),o=n(8060),a=n(7113);const i={id:"start",slug:"start",title:"Getting Started",description:"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!",sidebar_position:2},l=void 0,d={id:"start",title:"Getting Started",description:"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!",source:"@site/content/getting-started.md",sourceDirName:".",slug:"/start",permalink:"/start",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/getting-started.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"start",slug:"start",title:"Getting Started",description:"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Introduction",permalink:"/"},next:{title:"Listeners",permalink:"/listeners"}},c={},u=[{value:"Module",id:"module",level:2},{value:"Slash Commands",id:"slash-commands",level:2},{value:"Running the application",id:"running-the-application",level:2}];function h(e){const t={a:"a",admonition:"admonition",br:"br",code:"code",h2:"h2",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["In this article, you'll learn about the basics of nestcord, and how it integrates with ",(0,r.jsx)(t.a,{href:"https://nestjs.com/",children:"NestJS"}),"!"]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["Many of the concepts seen with nestcord are designed to be used like other components in a ",(0,r.jsx)(t.a,{href:"https://nestjs.com/",children:"NestJS"})," project.",(0,r.jsx)(t.br,{}),"\n","We recommend you to be familiar with the ",(0,r.jsx)(t.a,{href:"https://docs.nestjs.com/",children:"NestJS documentation"}),", especially its ",(0,r.jsx)(t.a,{href:"https://docs.nestjs.com/first-steps",children:"overview"})," section, before getting started."]})}),"\n",(0,r.jsxs)(t.p,{children:["The very first step is to install nestcord and its dependency, ",(0,r.jsx)(t.a,{href:"https://discord.js.org",children:(0,r.jsx)(t.code,{children:"Discord.js"})})]}),"\n",(0,r.jsxs)(o.A,{groupId:"npm2yarn",children:[(0,r.jsx)(a.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"npm install @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"yarn add @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"pnpm add @globalart/nestcord discord.js\n"})})})]}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["You need to install ",(0,r.jsx)(t.a,{href:"https://nodejs.org/en/",children:"Node.js"})," v16.0.0 or newer to use NestCord and Discord.js."]})}),"\n",(0,r.jsx)(t.h2,{id:"module",children:"Module"}),"\n",(0,r.jsx)(t.p,{children:"NestCord is a module like any others, and can be imported as such within your Nest application."}),"\n",(0,r.jsx)(t.admonition,{title:"NestJS modules",type:"note",children:(0,r.jsxs)(t.p,{children:["Not sure what modules are? Catch up by reading about them in ",(0,r.jsx)(t.a,{href:"https://docs.nestjs.com/modules",children:"NestJS"}),"!"]})}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="discord.module.ts"',children:"import { Module } from '@nestjs/common';\nimport { AppService } from './app.service';\nimport { IntentsBitField } from 'discord.js';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: process.env.DISCORD_TOKEN,\n intents: [IntentsBitField.Flags.Guilds],\n development: [process.env.DISCORD_DEVELOPMENT_GUILD_ID]\n })\n ],\n providers: [AppService]\n})\nexport class DiscordModule {}\n"})}),"\n",(0,r.jsx)(t.admonition,{type:"info",children:(0,r.jsxs)(t.p,{children:["Make sure to setup the correct ",(0,r.jsx)(t.strong,{children:(0,r.jsx)(t.a,{href:"https://discordjs.guide/popular-topics/intents.html#privileged-intents",children:"intents"})})," required by your application!"]})}),"\n",(0,r.jsxs)(t.p,{children:["The module arguments are an extension of discord.js ",(0,r.jsx)(t.a,{href:"https://discord.js.org/#/docs/discord.js/stable/typedef/ClientOptions",children:"ClientOptions"}),", in addition to 3 nestcord options: ",(0,r.jsx)(t.code,{children:"token"}),", ",(0,r.jsx)(t.code,{children:"prefix"})," and ",(0,r.jsx)(t.code,{children:"development"}),"."]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",children:"export interface NestCordModuleOptions extends DiscordClientOptions {\n token: string;\n prefix?: string | (message: Message) => string | Promise;\n development?: Snowflake[] | false;\n skipRegistration?: boolean;\n}\n"})}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Property"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Description"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"token"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"string"})}),(0,r.jsx)(t.td,{children:"Your Discord token"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"prefix"})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"string"})," or ",(0,r.jsx)(t.code,{children:"(message: Message) => string"})]}),(0,r.jsx)(t.td,{children:"The prefix for your bot"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"development"})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.code,{children:"Snowflake[]"})," or ",(0,r.jsx)(t.code,{children:"false"})]}),(0,r.jsx)(t.td,{children:"The development guilds for your bot"})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"skipRegistration"})}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.code,{children:"boolean"})}),(0,r.jsx)(t.td,{children:"Skip automatic registration of application commands"})]})]})]}),"\n",(0,r.jsx)(t.admonition,{title:"Warning",type:"caution",children:(0,r.jsxs)(t.p,{children:["If you have commands using the ",(0,r.jsx)(t.code,{children:"guilds"})," property, the global development argument ",(0,r.jsx)(t.strong,{children:"will not"})," overwrite it."]})}),"\n",(0,r.jsx)(t.h2,{id:"slash-commands",children:"Slash Commands"}),"\n",(0,r.jsxs)(t.p,{children:["The best way to interact with your users is to use ",(0,r.jsx)(t.a,{href:"https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ",children:"Slash commands"}),"!\nSlash commands allow you to create commands with precise arguments and choices, giving users the best experience."]}),"\n",(0,r.jsxs)(t.p,{children:["To create a command with NestCord, you can use the ",(0,r.jsx)(t.code,{children:"SlashCommand"})," decorator."]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @SlashCommand({\n name: 'ping',\n description: 'Ping command!'\n })\n public async onPing(@Context() [interaction]: SlashCommandContext) {\n return interaction.reply({ content: 'Pong!' });\n }\n}\n"})}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["When the client logs in, it will automatically register all of the commands.\nGlobal commands are cached for up to an hour, therefore to avoid the global commands cache, you should use the ",(0,r.jsx)(t.code,{children:"development"})," argument on the NestCord module. This will restrict the command to a single guild, preventing it from getting caught by the cache."]})}),"\n",(0,r.jsx)(t.h2,{id:"running-the-application",children:"Running the application"}),"\n",(0,r.jsx)(t.p,{children:"You can run the following command at your OS command prompt to start the application listening Discord API events:"}),"\n",(0,r.jsxs)(o.A,{groupId:"npm2yarn",children:[(0,r.jsx)(a.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ npm run start\n"})})}),(0,r.jsx)(a.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ yarn run start\n"})})}),(0,r.jsx)(a.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ pnpm run start\n"})})})]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7113:(e,t,n)=>{n.d(t,{A:()=>a});n(758);var r=n(3526);const s={tabItem:"tabItem_A6Wz"};var o=n(6070);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,a),hidden:n,children:t})}},8060:(e,t,n)=>{n.d(t,{A:()=>w});var r=n(758),s=n(3526),o=n(5394),a=n(5557),i=n(8063),l=n(5799),d=n(1836),c=n(8552);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,d.X)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const s=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l.aZ)(o),(0,r.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(s.location.search);t.set(o,e),s.replace({...s.location,search:t.toString()})}),[o,s])]}function x(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,o=h(e),[a,l]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[d,u]=m({queryString:n,groupId:s}),[x,j]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,o]=(0,c.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:s}),g=(()=>{const e=d??x;return p({value:e,tabValues:o})?e:null})();(0,i.A)((()=>{g&&l(g)}),[g]);return{selectedValue:a,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);l(e),u(e),j(e)}),[u,j,o]),tabValues:o}}var j=n(2253);const g={tabList:"tabList_UwLV",tabItem:"tabItem_Clxf"};var b=n(6070);function f(e){let{className:t,block:n,selectedValue:r,selectValue:a,tabValues:i}=e;const l=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.a_)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),s=i[n].value;s!==r&&(d(t),a(s))},u=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:i.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>l.push(e),onKeyDown:u,onClick:c,...o,className:(0,s.A)("tabs__item",g.tabItem,o?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=x(e);return(0,b.jsxs)("div",{className:(0,s.A)("tabs-container",g.tabList),children:[(0,b.jsx)(f,{...t,...e}),(0,b.jsx)(v,{...t,...e})]})}function w(e){const t=(0,j.A)();return(0,b.jsx)(y,{...e,children:u(e.children)},String(t))}},5710:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>i});var r=n(758);const s={},o=r.createContext(s);function a(e){const t=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5ca74542.8778d570.js b/assets/js/5ca74542.8778d570.js new file mode 100644 index 0000000..ed09a39 --- /dev/null +++ b/assets/js/5ca74542.8778d570.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[984],{3495:(n,t,e)=>{e.r(t),e.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>a,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var o=e(6070),i=e(5710);const s={id:"funding",title:"Funding",sidebar_position:4},r="Funding",c={id:"contributing/funding",title:"Funding",description:"NestCord is an open source project with its ongoing development made possible thanks to the support by the community.",source:"@site/content/contributing/funding.md",sourceDirName:"contributing",slug:"/contributing/funding",permalink:"/contributing/funding",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/funding.md",tags:[],version:"current",sidebarPosition:4,frontMatter:{id:"funding",title:"Funding",sidebar_position:4},sidebar:"docsSidebar",previous:{title:"Commit convention",permalink:"/contributing/commit-convention"}},u={},d=[];function l(n){const t={a:"a",br:"br",h1:"h1",li:"li",p:"p",ul:"ul",...(0,i.R)(),...n.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.h1,{id:"funding",children:"Funding"}),"\n",(0,o.jsxs)(t.p,{children:["NestCord is an open source project with its ongoing development made possible thanks to the support by the community.",(0,o.jsx)(t.br,{}),"\n","This library is a result of the long road, full of sleepless nights, working after hours, and busy weekends."]}),"\n",(0,o.jsx)(t.p,{children:"If you wish to support NestCord financially, thank you!\nYou can use the following methods to send your donation:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:["become a backer or sponsor on ",(0,o.jsx)(t.a,{href:"https://opencollective.com/GlobalArtInc",children:"OpenCollective"})]}),"\n"]})]})}function a(n={}){const{wrapper:t}={...(0,i.R)(),...n.components};return t?(0,o.jsx)(t,{...n,children:(0,o.jsx)(l,{...n})}):l(n)}},5710:(n,t,e)=>{e.d(t,{R:()=>r,x:()=>c});var o=e(758);const i={},s=o.createContext(i);function r(n){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof n?n(t):{...t,...n}}),[t,n])}function c(n){let t;return t=n.disableParentContext?"function"==typeof n.components?n.components(i):n.components||i:r(n.components),o.createElement(s.Provider,{value:t},n.children)}}}]); \ No newline at end of file diff --git a/assets/js/5ca74542.e6781872.js b/assets/js/5ca74542.e6781872.js deleted file mode 100644 index f5ebd63..0000000 --- a/assets/js/5ca74542.e6781872.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[984],{3495:(n,t,e)=>{e.r(t),e.d(t,{assets:()=>u,contentTitle:()=>r,default:()=>a,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var o=e(6070),i=e(5710);const s={id:"funding",title:"Funding",sidebar_position:4},r="Funding",c={id:"contributing/funding",title:"Funding",description:"NestCord is an open source project with its ongoing development made possible thanks to the support by the community.",source:"@site/content/contributing/funding.md",sourceDirName:"contributing",slug:"/contributing/funding",permalink:"/nestcord/contributing/funding",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/funding.md",tags:[],version:"current",sidebarPosition:4,frontMatter:{id:"funding",title:"Funding",sidebar_position:4},sidebar:"docsSidebar",previous:{title:"Commit convention",permalink:"/nestcord/contributing/commit-convention"}},u={},d=[];function l(n){const t={a:"a",br:"br",h1:"h1",li:"li",p:"p",ul:"ul",...(0,i.R)(),...n.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.h1,{id:"funding",children:"Funding"}),"\n",(0,o.jsxs)(t.p,{children:["NestCord is an open source project with its ongoing development made possible thanks to the support by the community.",(0,o.jsx)(t.br,{}),"\n","This library is a result of the long road, full of sleepless nights, working after hours, and busy weekends."]}),"\n",(0,o.jsx)(t.p,{children:"If you wish to support NestCord financially, thank you!\nYou can use the following methods to send your donation:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:["become a backer or sponsor on ",(0,o.jsx)(t.a,{href:"https://opencollective.com/GlobalArtInc",children:"OpenCollective"})]}),"\n"]})]})}function a(n={}){const{wrapper:t}={...(0,i.R)(),...n.components};return t?(0,o.jsx)(t,{...n,children:(0,o.jsx)(l,{...n})}):l(n)}},5710:(n,t,e)=>{e.d(t,{R:()=>r,x:()=>c});var o=e(758);const i={},s=o.createContext(i);function r(n){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof n?n(t):{...t,...n}}),[t,n])}function c(n){let t;return t=n.disableParentContext?"function"==typeof n.components?n.components(i):n.components||i:r(n.components),o.createElement(s.Provider,{value:t},n.children)}}}]); \ No newline at end of file diff --git a/assets/js/63e38a2b.1a10a071.js b/assets/js/63e38a2b.1a10a071.js new file mode 100644 index 0000000..484f2dc --- /dev/null +++ b/assets/js/63e38a2b.1a10a071.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[123],{765:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>s,metadata:()=>a,toc:()=>c});var r=o(6070),n=o(5710);const s={id:"stat-reporter",title:"Stat Reporter",sidebar_position:2},i=void 0,a={id:"recipes/stat-reporter",title:"Stat Reporter",description:"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services.",source:"@site/content/recipes/stat-reporter.md",sourceDirName:"recipes",slug:"/recipes/stat-reporter",permalink:"/recipes/stat-reporter",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/stat-reporter.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"stat-reporter",title:"Stat Reporter",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Localization",permalink:"/recipes/localization"},next:{title:"Validation",permalink:"/techniques/validation"}},d={},c=[{value:"Usage",id:"usage",level:2}];function l(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,n.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.p,{children:"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services."}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsxs)(t.p,{children:["Once the installation process is complete, we can import the ",(0,r.jsx)(t.code,{children:"NestCordStatReporterModule"})," with your ",(0,r.jsx)(t.code,{children:"NestCordModule"})," into the root ",(0,r.jsx)(t.code,{children:"AppModule"}),":"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",children:"import { Module } from '@nestjs/common';\nimport { AppService } from './app.service';\nimport { NestCordModule, \n NestCordStatReporterModule, \n StatCronExpression, \n NestCordLocalizationModule, \n DefaultLocalizationAdapter, \n UserResolver \n} from '@globalart/nestcord';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: process.env.DISCORD_TOKEN,\n intents: [\n IntentsBitField.Flags.Guilds,\n IntentsBitField.Flags.DirectMessages,\n IntentsBitField.Flags.GuildMembers,\n IntentsBitField.Flags.GuildMessages,\n IntentsBitField.Flags.MessageContent\n ],\n prefix: '!',\n development: [process.env.DISCORD_TEST_GUILD]\n }),\n NestCordStatReporterModule.forRoot({\n services: [\n {\n name: 'top.gg',\n url: 'https://top.gg/bots/:bot_id/stats',\n bodyData: { server_count: '{{serverCount}}', shard_count: '{{shardCount}}' },\n headerData: { Authorization: process.env.TOP_GG_TOKEN },\n schedule: StatCronExpression.EVERY_5_MINUTES // or you can use crontab expression like */1 * * * * ,\n },\n ],\n }),\n ],\n providers: [AppService]\n})\nexport class AppModule {\n}\n"})}),"\n",(0,r.jsxs)(t.p,{children:["In ",(0,r.jsx)(t.code,{children:"services"}),", all the services on which the bot is monitored should be listed, and the request body should be passed. ",(0,r.jsx)(t.code,{children:"{{serverCount}}"})," and ",(0,r.jsx)(t.code,{children:"{{shardCount}}"})," will be automatically replaced."]}),"\n",(0,r.jsx)(t.p,{children:"Congratulations! You have successfully register cronjob with NestCord!"})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},5710:(e,t,o)=>{o.d(t,{R:()=>i,x:()=>a});var r=o(758);const n={},s=r.createContext(n);function i(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function a(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/63e38a2b.7501b623.js b/assets/js/63e38a2b.7501b623.js deleted file mode 100644 index 341081f..0000000 --- a/assets/js/63e38a2b.7501b623.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[123],{765:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>a,contentTitle:()=>i,default:()=>p,frontMatter:()=>s,metadata:()=>d,toc:()=>c});var r=o(6070),n=o(5710);const s={id:"stat-reporter",title:"Stat Reporter",sidebar_position:2},i=void 0,d={id:"recipes/stat-reporter",title:"Stat Reporter",description:"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services.",source:"@site/content/recipes/stat-reporter.md",sourceDirName:"recipes",slug:"/recipes/stat-reporter",permalink:"/nestcord/recipes/stat-reporter",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/stat-reporter.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"stat-reporter",title:"Stat Reporter",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Localization",permalink:"/nestcord/recipes/localization"},next:{title:"Validation",permalink:"/nestcord/techniques/validation"}},a={},c=[{value:"Usage",id:"usage",level:2}];function l(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,n.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.p,{children:"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services."}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsxs)(t.p,{children:["Once the installation process is complete, we can import the ",(0,r.jsx)(t.code,{children:"NestCordStatReporterModule"})," with your ",(0,r.jsx)(t.code,{children:"NestCordModule"})," into the root ",(0,r.jsx)(t.code,{children:"AppModule"}),":"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",children:"import { Module } from '@nestjs/common';\nimport { AppService } from './app.service';\nimport { NestCordModule, \n NestCordStatReporterModule, \n StatCronExpression, \n NestCordLocalizationModule, \n DefaultLocalizationAdapter, \n UserResolver \n} from '@globalart/nestcord';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: process.env.DISCORD_TOKEN,\n intents: [\n IntentsBitField.Flags.Guilds,\n IntentsBitField.Flags.DirectMessages,\n IntentsBitField.Flags.GuildMembers,\n IntentsBitField.Flags.GuildMessages,\n IntentsBitField.Flags.MessageContent\n ],\n prefix: '!',\n development: [process.env.DISCORD_TEST_GUILD]\n }),\n NestCordStatReporterModule.forRoot({\n services: [\n {\n name: 'top.gg',\n url: 'https://top.gg/bots/:bot_id/stats',\n bodyData: { server_count: '{{serverCount}}', shard_count: '{{shardCount}}' },\n headerData: { Authorization: process.env.TOP_GG_TOKEN },\n schedule: StatCronExpression.EVERY_5_MINUTES // or you can use crontab expression like */1 * * * * ,\n },\n ],\n }),\n ],\n providers: [AppService]\n})\nexport class AppModule {\n}\n"})}),"\n",(0,r.jsxs)(t.p,{children:["In ",(0,r.jsx)(t.code,{children:"services"}),", all the services on which the bot is monitored should be listed, and the request body should be passed. ",(0,r.jsx)(t.code,{children:"{{serverCount}}"})," and ",(0,r.jsx)(t.code,{children:"{{shardCount}}"})," will be automatically replaced."]}),"\n",(0,r.jsx)(t.p,{children:"Congratulations! You have successfully register cronjob with NestCord!"})]})}function p(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},5710:(e,t,o)=>{o.d(t,{R:()=>i,x:()=>d});var r=o(758);const n={},s=r.createContext(n);function i(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function d(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6629c45f.57e58609.js b/assets/js/6629c45f.57e58609.js new file mode 100644 index 0000000..1f0b86c --- /dev/null +++ b/assets/js/6629c45f.57e58609.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[820],{7691:e=>{e.exports=JSON.parse('{"version":{"pluginId":"default","version":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","isLast":true,"docsSidebars":{"docsSidebar":[{"type":"link","label":"Introduction","href":"/","docId":"intro","unlisted":false},{"type":"link","label":"Getting Started","href":"/start","docId":"start","unlisted":false},{"type":"link","label":"Listeners","href":"/listeners","docId":"listeners","unlisted":false},{"type":"category","label":"Interactions","collapsible":true,"collapsed":false,"items":[{"type":"link","label":"Slash Commands","href":"/interactions/slash-commands","docId":"interactions/slash-commands","unlisted":false},{"type":"link","label":"Context Menus","href":"/interactions/context-menus","docId":"interactions/context-menus","unlisted":false},{"type":"link","label":"Message Components","href":"/interactions/message-components","docId":"interactions/message-components","unlisted":false},{"type":"link","label":"Modals","href":"/interactions/modals","docId":"interactions/modals","unlisted":false}]},{"type":"link","label":"Text Commands","href":"/text-commands","docId":"text-commands","unlisted":false},{"type":"category","label":"Interceptors","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Defer command","href":"/interceptors/defer-interceptor","docId":"interceptors/defer-interceptor","unlisted":false}]},{"type":"category","label":"Recipes","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Pagination","href":"/recipes/pagination","docId":"recipes/pagination","unlisted":false},{"type":"link","label":"Localization","href":"/recipes/localization","docId":"recipes/localization","unlisted":false},{"type":"link","label":"Stat Reporter","href":"/recipes/stat-reporter","docId":"recipes/stat-reporter","unlisted":false}]},{"type":"category","label":"Techniques","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Validation","href":"/techniques/validation","docId":"techniques/validation","unlisted":false},{"type":"link","label":"Sharding","href":"/techniques/sharding","docId":"techniques/sharding","unlisted":false},{"type":"link","label":"Async Configuration","href":"/techniques/async-configuration","docId":"techniques/async-configuration","unlisted":false},{"type":"link","label":"Standalone application","href":"/techniques/standalone-application","docId":"techniques/standalone-application","unlisted":false},{"type":"link","label":"Client Providers","href":"/techniques/client-providers","docId":"techniques/client-providers","unlisted":false}]},{"type":"category","label":"Contributing","collapsible":true,"collapsed":false,"items":[{"type":"link","label":"Contribution Guide","href":"/contributing/contribution-guide","docId":"contributing/contribution-guide","unlisted":false},{"type":"link","label":"Code of Conduct","href":"/contributing/code-of-conduct","docId":"contributing/code-of-conduct","unlisted":false},{"type":"link","label":"Commit convention","href":"/contributing/commit-convention","docId":"contributing/commit-convention","unlisted":false},{"type":"link","label":"Funding","href":"/contributing/funding","docId":"contributing/funding","unlisted":false}]}]},"docs":{"contributing/code-of-conduct":{"id":"contributing/code-of-conduct","title":"Code of Conduct","description":"Our Pledge","sidebar":"docsSidebar"},"contributing/commit-convention":{"id":"contributing/commit-convention","title":"Commit convention","description":"Git Commit Message Convention","sidebar":"docsSidebar"},"contributing/contribution-guide":{"id":"contributing/contribution-guide","title":"Contribution Guide","description":"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a","sidebar":"docsSidebar"},"contributing/funding":{"id":"contributing/funding","title":"Funding","description":"NestCord is an open source project with its ongoing development made possible thanks to the support by the community.","sidebar":"docsSidebar"},"interactions/context-menus":{"id":"interactions/context-menus","title":"Context Menus","description":"User commands and message commands are now live! These commands appear on context menus for users and messages, with more to come in the future.","sidebar":"docsSidebar"},"interactions/message-components":{"id":"interactions/message-components","title":"Message Components","description":"Message components \u2014 we\'ll call them \\"components\\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They\'re accessible, customizable, and easy to use.","sidebar":"docsSidebar"},"interactions/modals":{"id":"interactions/modals","title":"Modals","description":"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We\'ll cover how to create, show, and receive modal forms using nestcord","sidebar":"docsSidebar"},"interactions/slash-commands":{"id":"interactions/slash-commands","title":"Slash Commands","description":"Slash Commands are the new, exciting way to build and interact with bots on Discord. With Slash Commands, all you have to do is","sidebar":"docsSidebar"},"interceptors/defer-interceptor":{"id":"interceptors/defer-interceptor","title":"Defer command","description":"Interceptor added interaction.deferReply() to the beiginning of the code","sidebar":"docsSidebar"},"intro":{"id":"intro","title":"Introduction","description":"A module for creating Discord bots using NestJS, based on Discord.js.","sidebar":"docsSidebar"},"listeners":{"id":"listeners","title":"Listeners","description":"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.","sidebar":"docsSidebar"},"recipes/localization":{"id":"recipes/localization","title":"Localization","description":"Is a lightweight localization module for NestCord. It allows you to easily localize your bot\'s","sidebar":"docsSidebar"},"recipes/pagination":{"id":"recipes/pagination","title":"Pagination","description":"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and","sidebar":"docsSidebar"},"recipes/stat-reporter":{"id":"recipes/stat-reporter","title":"Stat Reporter","description":"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services.","sidebar":"docsSidebar"},"start":{"id":"start","title":"Getting Started","description":"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!","sidebar":"docsSidebar"},"techniques/async-configuration":{"id":"techniques/async-configuration","title":"Async Configuration","description":"When you need to pass module options asynchronously instead of statically, use the .forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration.","sidebar":"docsSidebar"},"techniques/client-providers":{"id":"techniques/client-providers","title":"Client Providers","description":"NestCord have snippets to access the client and its properties in your application.","sidebar":"docsSidebar"},"techniques/sharding":{"id":"techniques/sharding","title":"Sharding","description":"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works.","sidebar":"docsSidebar"},"techniques/standalone-application":{"id":"techniques/standalone-application","title":"Standalone application","description":"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don\'t need a web server, you can remove Express.","sidebar":"docsSidebar"},"techniques/validation":{"id":"techniques/validation","title":"Validation","description":"The ValidationPipe is a built-in pipe that can be used to validate data coming from the client. It uses class-validator package under the hood. The ValidationPipe provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module.","sidebar":"docsSidebar"},"text-commands":{"id":"text-commands","title":"Text Commands","description":"Text commands are the most common type of command. They are used to send a message to the channel.","sidebar":"docsSidebar"}}}}')}}]); \ No newline at end of file diff --git a/assets/js/6c4d718c.6fdd585d.js b/assets/js/6c4d718c.6fdd585d.js deleted file mode 100644 index 02d5ab3..0000000 --- a/assets/js/6c4d718c.6fdd585d.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[713],{1309:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>l,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var t=o(6070),i=o(5710);const s={id:"sharding",title:"Sharding",sidebar_position:1},r=void 0,a={id:"techniques/sharding",title:"Sharding",description:"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works.",source:"@site/content/techniques/sharding.md",sourceDirName:"techniques",slug:"/techniques/sharding",permalink:"/nestcord/techniques/sharding",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/sharding.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"sharding",title:"Sharding",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Validation",permalink:"/nestcord/techniques/validation"},next:{title:"Async Configuration",permalink:"/nestcord/techniques/async-configuration"}},c={},d=[];function h(e){const n={a:"a",admonition:"admonition",code:"code",li:"li",ol:"ol",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.p,{children:"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works."}),"\n",(0,t.jsx)(n.admonition,{type:"caution",children:(0,t.jsxs)(n.p,{children:["If you are running the bot as part of a webserver within NestJS, then in order to implement sharding you must understand that initialising ",(0,t.jsx)(n.code,{children:"nestcord"})," within your HTTP server process isn't going to be a viable option. So we're going to have to split the two into their own independent processes. This doesn't mean you can't share code between the two, just that they will be running on different processes. You could consider your \"bot\" application as a microservice of sorts."]})}),"\n",(0,t.jsxs)(n.ol,{children:["\n",(0,t.jsxs)(n.li,{children:["In your ",(0,t.jsx)(n.code,{children:"src"})," directory, create a new ",(0,t.jsx)(n.code,{children:"bot.ts"})," file, this will be used to instantiate the bot as a standalone application wth some slight differences. The ",(0,t.jsx)(n.code,{children:"DiscordModule"})," cannot be imported within your ",(0,t.jsx)(n.code,{children:"AppModule"}),". This is because we do not want any bot processes on unsharded processes, so if you need to share code between the two, you should import the necessary modules into your ",(0,t.jsx)(n.code,{children:"DiscordModule"})," or alternatively, create a ",(0,t.jsx)(n.code,{children:"SharedModule"})," which is imported both into your ",(0,t.jsx)(n.code,{children:"AppModule"})," and ",(0,t.jsx)(n.code,{children:"DiscordModule"}),"."]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestFactory } from '@nestjs/core';\nimport { DiscordModule } from './discord/discord.module';\n\nasync function bootstrap() {\n await NestFactory.createApplicationContext(DiscordModule);\n}\n\nbootstrap();\n"})}),"\n",(0,t.jsxs)(n.admonition,{type:"info",children:[(0,t.jsxs)(n.p,{children:["You may also need to add a ",(0,t.jsx)(n.code,{children:"webpack.config.js"})," file to your root directory which exports the ",(0,t.jsx)(n.code,{children:"bot.ts"})," file as it's not automatically exported with the application due to how the ",(0,t.jsx)(n.code,{children:"bot.ts"})," file is used within another process which webpack is unable to detect. You can use the following snippet to achieve this:"]}),(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"const Path = require('path');\n\nmodule.exports = function (options) {\n return {\n ...options,\n entry: {\n main: options.entry,\n bot: Path.join(__dirname, 'src', 'bot.ts')\n },\n output: {\n filename: '[name].js'\n }\n };\n};\n"})})]}),"\n",(0,t.jsxs)(n.ol,{start:"2",children:["\n",(0,t.jsxs)(n.li,{children:["Modify your ",(0,t.jsx)(n.code,{children:"main.ts"})," file to create a new ",(0,t.jsx)(n.code,{children:"ShardingManager"})," instance which calls your ",(0,t.jsx)(n.code,{children:"bot.js"})," file (not .ts extension), specifying a .ts extension will cause errors as this is executed only after your code has been transpiled into JavaScript. You can use the snippet below as an example:"]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\nimport * as Path from 'path';\n\nexport async function bootstrap() {\n const app = await NestFactory.create(AppModule);\n const port = 80;\n\n await app.listen(port);\n\n const manager = new ShardingManager(Path.join(__dirname, 'bot.js'), {\n token: 'secret'\n });\n\n manager.spawn();\n\n manager.on('shardCreate', shard => {\n shard.on('reconnecting', () => {\n console.log(`Reconnecting shard: [${shard.id}]`);\n });\n\n shard.on('spawn', () => {\n console.log(`Spawned shard: [${shard.id}]`);\n });\n\n shard.on('ready', () => {\n console.log(` Shard [${shard.id}] is ready`);\n });\n\n shard.on('death', () => {\n console.log(`Died shard: [${shard.id}]`);\n });\n\n shard.on('error', err => {\n console.log(`Error in [${shard.id}] with : ${err} `);\n shard.respawn();\n });\n });\n}\nbootstrap();\n"})}),"\n",(0,t.jsxs)(n.ol,{start:"3",children:["\n",(0,t.jsxs)(n.li,{children:["Now when you bootstrap your application, your ",(0,t.jsx)(n.code,{children:"bot.ts"})," context is created on a sharded process."]}),"\n"]}),"\n",(0,t.jsx)(n.admonition,{type:"tip",children:(0,t.jsxs)(n.p,{children:["If you are running into further issues and require cross-hosting your bot application, then just swap the ",(0,t.jsx)(n.code,{children:"ShardingManager"})," out for other sharding packages like the ",(0,t.jsx)(n.a,{href:"https://github.com/meister03/discord-hybrid-sharding",children:"discord-hybrid-sharding"})," which is required for the ",(0,t.jsx)(n.a,{href:"https://github.com/meister03/discord-cross-hosting",children:"discord-cross-hosting"})," package."]})})]})}function l(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5710:(e,n,o)=>{o.d(n,{R:()=>r,x:()=>a});var t=o(758);const i={},s=t.createContext(i);function r(e){const n=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6c4d718c.c7af60f2.js b/assets/js/6c4d718c.c7af60f2.js new file mode 100644 index 0000000..c8f78c1 --- /dev/null +++ b/assets/js/6c4d718c.c7af60f2.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[713],{1309:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>l,frontMatter:()=>s,metadata:()=>a,toc:()=>d});var t=o(6070),i=o(5710);const s={id:"sharding",title:"Sharding",sidebar_position:1},r=void 0,a={id:"techniques/sharding",title:"Sharding",description:"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works.",source:"@site/content/techniques/sharding.md",sourceDirName:"techniques",slug:"/techniques/sharding",permalink:"/techniques/sharding",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/sharding.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"sharding",title:"Sharding",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Validation",permalink:"/techniques/validation"},next:{title:"Async Configuration",permalink:"/techniques/async-configuration"}},c={},d=[];function h(e){const n={a:"a",admonition:"admonition",code:"code",li:"li",ol:"ol",p:"p",pre:"pre",...(0,i.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.p,{children:"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works."}),"\n",(0,t.jsx)(n.admonition,{type:"caution",children:(0,t.jsxs)(n.p,{children:["If you are running the bot as part of a webserver within NestJS, then in order to implement sharding you must understand that initialising ",(0,t.jsx)(n.code,{children:"nestcord"})," within your HTTP server process isn't going to be a viable option. So we're going to have to split the two into their own independent processes. This doesn't mean you can't share code between the two, just that they will be running on different processes. You could consider your \"bot\" application as a microservice of sorts."]})}),"\n",(0,t.jsxs)(n.ol,{children:["\n",(0,t.jsxs)(n.li,{children:["In your ",(0,t.jsx)(n.code,{children:"src"})," directory, create a new ",(0,t.jsx)(n.code,{children:"bot.ts"})," file, this will be used to instantiate the bot as a standalone application wth some slight differences. The ",(0,t.jsx)(n.code,{children:"DiscordModule"})," cannot be imported within your ",(0,t.jsx)(n.code,{children:"AppModule"}),". This is because we do not want any bot processes on unsharded processes, so if you need to share code between the two, you should import the necessary modules into your ",(0,t.jsx)(n.code,{children:"DiscordModule"})," or alternatively, create a ",(0,t.jsx)(n.code,{children:"SharedModule"})," which is imported both into your ",(0,t.jsx)(n.code,{children:"AppModule"})," and ",(0,t.jsx)(n.code,{children:"DiscordModule"}),"."]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestFactory } from '@nestjs/core';\nimport { DiscordModule } from './discord/discord.module';\n\nasync function bootstrap() {\n await NestFactory.createApplicationContext(DiscordModule);\n}\n\nbootstrap();\n"})}),"\n",(0,t.jsxs)(n.admonition,{type:"info",children:[(0,t.jsxs)(n.p,{children:["You may also need to add a ",(0,t.jsx)(n.code,{children:"webpack.config.js"})," file to your root directory which exports the ",(0,t.jsx)(n.code,{children:"bot.ts"})," file as it's not automatically exported with the application due to how the ",(0,t.jsx)(n.code,{children:"bot.ts"})," file is used within another process which webpack is unable to detect. You can use the following snippet to achieve this:"]}),(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"const Path = require('path');\n\nmodule.exports = function (options) {\n return {\n ...options,\n entry: {\n main: options.entry,\n bot: Path.join(__dirname, 'src', 'bot.ts')\n },\n output: {\n filename: '[name].js'\n }\n };\n};\n"})})]}),"\n",(0,t.jsxs)(n.ol,{start:"2",children:["\n",(0,t.jsxs)(n.li,{children:["Modify your ",(0,t.jsx)(n.code,{children:"main.ts"})," file to create a new ",(0,t.jsx)(n.code,{children:"ShardingManager"})," instance which calls your ",(0,t.jsx)(n.code,{children:"bot.js"})," file (not .ts extension), specifying a .ts extension will cause errors as this is executed only after your code has been transpiled into JavaScript. You can use the snippet below as an example:"]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestFactory } from '@nestjs/core';\nimport { AppModule } from './app.module';\nimport * as Path from 'path';\n\nexport async function bootstrap() {\n const app = await NestFactory.create(AppModule);\n const port = 80;\n\n await app.listen(port);\n\n const manager = new ShardingManager(Path.join(__dirname, 'bot.js'), {\n token: 'secret'\n });\n\n manager.spawn();\n\n manager.on('shardCreate', shard => {\n shard.on('reconnecting', () => {\n console.log(`Reconnecting shard: [${shard.id}]`);\n });\n\n shard.on('spawn', () => {\n console.log(`Spawned shard: [${shard.id}]`);\n });\n\n shard.on('ready', () => {\n console.log(` Shard [${shard.id}] is ready`);\n });\n\n shard.on('death', () => {\n console.log(`Died shard: [${shard.id}]`);\n });\n\n shard.on('error', err => {\n console.log(`Error in [${shard.id}] with : ${err} `);\n shard.respawn();\n });\n });\n}\nbootstrap();\n"})}),"\n",(0,t.jsxs)(n.ol,{start:"3",children:["\n",(0,t.jsxs)(n.li,{children:["Now when you bootstrap your application, your ",(0,t.jsx)(n.code,{children:"bot.ts"})," context is created on a sharded process."]}),"\n"]}),"\n",(0,t.jsx)(n.admonition,{type:"tip",children:(0,t.jsxs)(n.p,{children:["If you are running into further issues and require cross-hosting your bot application, then just swap the ",(0,t.jsx)(n.code,{children:"ShardingManager"})," out for other sharding packages like the ",(0,t.jsx)(n.a,{href:"https://github.com/meister03/discord-hybrid-sharding",children:"discord-hybrid-sharding"})," which is required for the ",(0,t.jsx)(n.a,{href:"https://github.com/meister03/discord-cross-hosting",children:"discord-cross-hosting"})," package."]})})]})}function l(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(h,{...e})}):h(e)}},5710:(e,n,o)=>{o.d(n,{R:()=>r,x:()=>a});var t=o(758);const i={},s=t.createContext(i);function r(e){const n=t.useContext(s);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),t.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/6d50398e.8db4c495.js b/assets/js/6d50398e.8db4c495.js deleted file mode 100644 index fe702a3..0000000 --- a/assets/js/6d50398e.8db4c495.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[767],{384:e=>{e.exports=JSON.parse('{"version":{"pluginId":"default","version":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","isLast":true,"docsSidebars":{"docsSidebar":[{"type":"link","label":"Introduction","href":"/nestcord/","docId":"intro","unlisted":false},{"type":"link","label":"Getting Started","href":"/nestcord/start","docId":"start","unlisted":false},{"type":"link","label":"Listeners","href":"/nestcord/listeners","docId":"listeners","unlisted":false},{"type":"category","label":"Interactions","collapsible":true,"collapsed":false,"items":[{"type":"link","label":"Slash Commands","href":"/nestcord/interactions/slash-commands","docId":"interactions/slash-commands","unlisted":false},{"type":"link","label":"Context Menus","href":"/nestcord/interactions/context-menus","docId":"interactions/context-menus","unlisted":false},{"type":"link","label":"Message Components","href":"/nestcord/interactions/message-components","docId":"interactions/message-components","unlisted":false},{"type":"link","label":"Modals","href":"/nestcord/interactions/modals","docId":"interactions/modals","unlisted":false}]},{"type":"link","label":"Text Commands","href":"/nestcord/text-commands","docId":"text-commands","unlisted":false},{"type":"category","label":"Interceptors","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Defer command","href":"/nestcord/interceptors/defer-interceptor","docId":"interceptors/defer-interceptor","unlisted":false}]},{"type":"category","label":"Recipes","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Pagination","href":"/nestcord/recipes/pagination","docId":"recipes/pagination","unlisted":false},{"type":"link","label":"Localization","href":"/nestcord/recipes/localization","docId":"recipes/localization","unlisted":false},{"type":"link","label":"Stat Reporter","href":"/nestcord/recipes/stat-reporter","docId":"recipes/stat-reporter","unlisted":false}]},{"type":"category","label":"Techniques","collapsible":true,"collapsed":true,"items":[{"type":"link","label":"Validation","href":"/nestcord/techniques/validation","docId":"techniques/validation","unlisted":false},{"type":"link","label":"Sharding","href":"/nestcord/techniques/sharding","docId":"techniques/sharding","unlisted":false},{"type":"link","label":"Async Configuration","href":"/nestcord/techniques/async-configuration","docId":"techniques/async-configuration","unlisted":false},{"type":"link","label":"Standalone application","href":"/nestcord/techniques/standalone-application","docId":"techniques/standalone-application","unlisted":false},{"type":"link","label":"Client Providers","href":"/nestcord/techniques/client-providers","docId":"techniques/client-providers","unlisted":false}]},{"type":"category","label":"Contributing","collapsible":true,"collapsed":false,"items":[{"type":"link","label":"Contribution Guide","href":"/nestcord/contributing/contribution-guide","docId":"contributing/contribution-guide","unlisted":false},{"type":"link","label":"Code of Conduct","href":"/nestcord/contributing/code-of-conduct","docId":"contributing/code-of-conduct","unlisted":false},{"type":"link","label":"Commit convention","href":"/nestcord/contributing/commit-convention","docId":"contributing/commit-convention","unlisted":false},{"type":"link","label":"Funding","href":"/nestcord/contributing/funding","docId":"contributing/funding","unlisted":false}]}]},"docs":{"contributing/code-of-conduct":{"id":"contributing/code-of-conduct","title":"Code of Conduct","description":"Our Pledge","sidebar":"docsSidebar"},"contributing/commit-convention":{"id":"contributing/commit-convention","title":"Commit convention","description":"Git Commit Message Convention","sidebar":"docsSidebar"},"contributing/contribution-guide":{"id":"contributing/contribution-guide","title":"Contribution Guide","description":"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a","sidebar":"docsSidebar"},"contributing/funding":{"id":"contributing/funding","title":"Funding","description":"NestCord is an open source project with its ongoing development made possible thanks to the support by the community.","sidebar":"docsSidebar"},"interactions/context-menus":{"id":"interactions/context-menus","title":"Context Menus","description":"User commands and message commands are now live! These commands appear on context menus for users and messages, with more to come in the future.","sidebar":"docsSidebar"},"interactions/message-components":{"id":"interactions/message-components","title":"Message Components","description":"Message components \u2014 we\'ll call them \\"components\\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They\'re accessible, customizable, and easy to use.","sidebar":"docsSidebar"},"interactions/modals":{"id":"interactions/modals","title":"Modals","description":"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We\'ll cover how to create, show, and receive modal forms using nestcord","sidebar":"docsSidebar"},"interactions/slash-commands":{"id":"interactions/slash-commands","title":"Slash Commands","description":"Slash Commands are the new, exciting way to build and interact with bots on Discord. With Slash Commands, all you have to do is","sidebar":"docsSidebar"},"interceptors/defer-interceptor":{"id":"interceptors/defer-interceptor","title":"Defer command","description":"Interceptor added interaction.deferReply() to the beiginning of the code","sidebar":"docsSidebar"},"intro":{"id":"intro","title":"Introduction","description":"A module for creating Discord bots using NestJS, based on Discord.js.","sidebar":"docsSidebar"},"listeners":{"id":"listeners","title":"Listeners","description":"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.","sidebar":"docsSidebar"},"recipes/localization":{"id":"recipes/localization","title":"Localization","description":"Is a lightweight localization module for NestCord. It allows you to easily localize your bot\'s","sidebar":"docsSidebar"},"recipes/pagination":{"id":"recipes/pagination","title":"Pagination","description":"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and","sidebar":"docsSidebar"},"recipes/stat-reporter":{"id":"recipes/stat-reporter","title":"Stat Reporter","description":"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services.","sidebar":"docsSidebar"},"start":{"id":"start","title":"Getting Started","description":"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!","sidebar":"docsSidebar"},"techniques/async-configuration":{"id":"techniques/async-configuration","title":"Async Configuration","description":"When you need to pass module options asynchronously instead of statically, use the .forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration.","sidebar":"docsSidebar"},"techniques/client-providers":{"id":"techniques/client-providers","title":"Client Providers","description":"NestCord have snippets to access the client and its properties in your application.","sidebar":"docsSidebar"},"techniques/sharding":{"id":"techniques/sharding","title":"Sharding","description":"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works.","sidebar":"docsSidebar"},"techniques/standalone-application":{"id":"techniques/standalone-application","title":"Standalone application","description":"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don\'t need a web server, you can remove Express.","sidebar":"docsSidebar"},"techniques/validation":{"id":"techniques/validation","title":"Validation","description":"The ValidationPipe is a built-in pipe that can be used to validate data coming from the client. It uses class-validator package under the hood. The ValidationPipe provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module.","sidebar":"docsSidebar"},"text-commands":{"id":"text-commands","title":"Text Commands","description":"Text commands are the most common type of command. They are used to send a message to the channel.","sidebar":"docsSidebar"}}}}')}}]); \ No newline at end of file diff --git a/assets/js/717a4525.2078c5ad.js b/assets/js/717a4525.2078c5ad.js deleted file mode 100644 index d9395cc..0000000 --- a/assets/js/717a4525.2078c5ad.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[365],{4073:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>r,default:()=>l,frontMatter:()=>a,metadata:()=>m,toc:()=>i});var o=n(6070),s=n(5710);const a={id:"text-commands",slug:"text-commands",title:"Text Commands",description:"Text commands are the most common type of command. They are used to send a message to the channel.",sidebar_position:5},r=void 0,m={id:"text-commands",title:"Text Commands",description:"Text commands are the most common type of command. They are used to send a message to the channel.",source:"@site/content/text-commands.md",sourceDirName:".",slug:"/text-commands",permalink:"/nestcord/text-commands",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/text-commands.md",tags:[],version:"current",sidebarPosition:5,frontMatter:{id:"text-commands",slug:"text-commands",title:"Text Commands",description:"Text commands are the most common type of command. They are used to send a message to the channel.",sidebar_position:5},sidebar:"docsSidebar",previous:{title:"Modals",permalink:"/nestcord/interactions/modals"},next:{title:"Defer command",permalink:"/nestcord/interceptors/defer-interceptor"}},c={},i=[{value:"Arguments",id:"arguments",level:2}];function d(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",img:"img",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.admonition,{type:"caution",children:[(0,o.jsx)(t.p,{children:"A text command is dependent on the content of the message but unfortunately, Discord plans to remove message content for verified bots and\napps, those with 100 or more servers. Hence, You cannot use text commands if your bot cannot access message content."}),(0,o.jsx)(t.p,{children:(0,o.jsx)(t.a,{href:"https://support-dev.discord.com/hc/en-us/articles/4404772028055-Message-Content-Access-Deprecation-for-Verified-Bots",children:"Read discord message here"})})]}),"\n",(0,o.jsxs)(t.p,{children:["Create a simple command handler for messages using ",(0,o.jsx)(t.code,{children:"@TextCommand"}),"."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, TextCommand, TextCommandContext, Arguments } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @TextCommand({\n name: 'ping',\n description: 'Ping command!',\n })\n public onPing(@Context() [message]: TextCommandContext) {\n return message.reply('pong!');\n }\n}\n"})}),"\n",(0,o.jsx)(t.p,{children:"If all goes well, you should see something like this:"}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.img,{alt:"Text Command",src:n(7667).A+"",title:"Text Command",width:"794",height:"200"})}),"\n",(0,o.jsx)(t.h2,{id:"arguments",children:"Arguments"}),"\n",(0,o.jsx)(t.p,{children:"You can also use arguments with text commands. Arguments are the words after the command name."}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, TextCommand, TextCommandContext, Arguments } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @TextCommand({\n name: 'echo',\n description: 'Echo command!',\n })\n public onEcho(@Context() [message]: TextCommandContext, @Arguments() args: string[]) {\n return message.reply(args.join(' '));\n }\n}\n"})})]})}function l(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},7667:(e,t,n)=>{n.d(t,{A:()=>o});const o=n.p+"assets/images/text_command-2eec6e27036b4cfe0bae1a98079b6135.png"},5710:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>m});var o=n(758);const s={},a=o.createContext(s);function r(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function m(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:r(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/717a4525.8dacc82a.js b/assets/js/717a4525.8dacc82a.js new file mode 100644 index 0000000..b4b702f --- /dev/null +++ b/assets/js/717a4525.8dacc82a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[365],{4073:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>m,default:()=>l,frontMatter:()=>a,metadata:()=>r,toc:()=>i});var o=n(6070),s=n(5710);const a={id:"text-commands",slug:"text-commands",title:"Text Commands",description:"Text commands are the most common type of command. They are used to send a message to the channel.",sidebar_position:5},m=void 0,r={id:"text-commands",title:"Text Commands",description:"Text commands are the most common type of command. They are used to send a message to the channel.",source:"@site/content/text-commands.md",sourceDirName:".",slug:"/text-commands",permalink:"/text-commands",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/text-commands.md",tags:[],version:"current",sidebarPosition:5,frontMatter:{id:"text-commands",slug:"text-commands",title:"Text Commands",description:"Text commands are the most common type of command. They are used to send a message to the channel.",sidebar_position:5},sidebar:"docsSidebar",previous:{title:"Modals",permalink:"/interactions/modals"},next:{title:"Defer command",permalink:"/interceptors/defer-interceptor"}},c={},i=[{value:"Arguments",id:"arguments",level:2}];function d(e){const t={a:"a",admonition:"admonition",code:"code",h2:"h2",img:"img",p:"p",pre:"pre",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(t.admonition,{type:"caution",children:[(0,o.jsx)(t.p,{children:"A text command is dependent on the content of the message but unfortunately, Discord plans to remove message content for verified bots and\napps, those with 100 or more servers. Hence, You cannot use text commands if your bot cannot access message content."}),(0,o.jsx)(t.p,{children:(0,o.jsx)(t.a,{href:"https://support-dev.discord.com/hc/en-us/articles/4404772028055-Message-Content-Access-Deprecation-for-Verified-Bots",children:"Read discord message here"})})]}),"\n",(0,o.jsxs)(t.p,{children:["Create a simple command handler for messages using ",(0,o.jsx)(t.code,{children:"@TextCommand"}),"."]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, TextCommand, TextCommandContext, Arguments } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @TextCommand({\n name: 'ping',\n description: 'Ping command!',\n })\n public onPing(@Context() [message]: TextCommandContext) {\n return message.reply('pong!');\n }\n}\n"})}),"\n",(0,o.jsx)(t.p,{children:"If all goes well, you should see something like this:"}),"\n",(0,o.jsx)(t.p,{children:(0,o.jsx)(t.img,{alt:"Text Command",src:n(7667).A+"",title:"Text Command",width:"794",height:"200"})}),"\n",(0,o.jsx)(t.h2,{id:"arguments",children:"Arguments"}),"\n",(0,o.jsx)(t.p,{children:"You can also use arguments with text commands. Arguments are the words after the command name."}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, TextCommand, TextCommandContext, Arguments } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @TextCommand({\n name: 'echo',\n description: 'Echo command!',\n })\n public onEcho(@Context() [message]: TextCommandContext, @Arguments() args: string[]) {\n return message.reply(args.join(' '));\n }\n}\n"})})]})}function l(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},7667:(e,t,n)=>{n.d(t,{A:()=>o});const o=n.p+"assets/images/text_command-2eec6e27036b4cfe0bae1a98079b6135.png"},5710:(e,t,n)=>{n.d(t,{R:()=>m,x:()=>r});var o=n(758);const s={},a=o.createContext(s);function m(e){const t=o.useContext(a);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:m(e.components),o.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7d07d949.c681836c.js b/assets/js/7d07d949.c681836c.js deleted file mode 100644 index 3f816bf..0000000 --- a/assets/js/7d07d949.c681836c.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[981],{2536:(e,t,d)=>{d.r(t),d.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>o,frontMatter:()=>r,metadata:()=>l,toc:()=>a});var s=d(6070),n=d(5710);const r={id:"listeners",slug:"listeners",title:"Listeners",description:"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.",sidebar_position:3},i=void 0,l={id:"listeners",title:"Listeners",description:"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.",source:"@site/content/listeners.md",sourceDirName:".",slug:"/listeners",permalink:"/nestcord/listeners",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/listeners.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{id:"listeners",slug:"listeners",title:"Listeners",description:"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Getting Started",permalink:"/nestcord/start"},next:{title:"Slash Commands",permalink:"/nestcord/interactions/slash-commands"}},c={},a=[{value:"Context",id:"context",level:2},{value:"Custom Events",id:"custom-events",level:2},{value:"Channel Events",id:"channel-events",level:3},{value:"Guild Events",id:"guild-events",level:3},{value:"Guild Audit Log Events",id:"guild-audit-log-events",level:4},{value:"Guild Member Events",id:"guild-member-events",level:4},{value:"Role Update Events",id:"role-update-events",level:4},{value:"Thread Update Events",id:"thread-update-events",level:4},{value:"Message Events",id:"message-events",level:3},{value:"Presence Events",id:"presence-events",level:3},{value:"User Events",id:"user-events",level:3},{value:"Voice Events",id:"voice-events",level:3}];function h(e){const t={a:"a",admonition:"admonition",br:"br",code:"code",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["NestCord supports interacting with all ",(0,s.jsx)(t.a,{href:"https://discord.js.org/#/docs/main/stable/class/Client#Events",children:"discord events"})," via the ",(0,s.jsx)(t.code,{children:"@On"}),"\nand ",(0,s.jsx)(t.code,{children:"@Once"})," decorator.",(0,s.jsx)(t.br,{}),"\n","While the best practice is to use the more specific decorators when possible, this is useful if you wish to use features NestCord doesn't\nsupport via custom decorators, to interact with the raw requests, or to listen to all events using a decorator such as ",(0,s.jsx)(t.code,{children:"interactionCreate"}),"."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import {Injectable, Logger} from '@nestjs/common';\nimport {Once, On, Context, ContextOf} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n private readonly logger = new Logger(AppService.name);\n\n @Once('ready')\n public onReady(@Context() [client]: ContextOf<'ready'>) {\n this.logger.log(`Bot logged in as ${client.user.username}`);\n }\n\n @On('warn')\n public onWarn(@Context() [message]: ContextOf<'warn'>) {\n this.logger.warn(message);\n }\n}\n"})}),"\n",(0,s.jsx)(t.admonition,{title:"Warning",type:"caution",children:(0,s.jsxs)(t.p,{children:["If you use global filters, guards or interceptors, they will be triggered once per event!",(0,s.jsx)(t.br,{}),"\n","This means if you are replying to the message in guards, you can run into issues with duplicated responses or invalid interactions.\nHave a look at the ",(0,s.jsx)(t.code,{children:"NestCordExecutionContext.getInfo()"})," metadata to learn more about the current context."]})}),"\n",(0,s.jsx)(t.h2,{id:"context",children:"Context"}),"\n",(0,s.jsxs)(t.p,{children:["You might have noticed the ",(0,s.jsx)(t.code,{children:"@Context"})," decorator in the last snippet: This is used to inject the event context within the method.\nAs there are many type of events, its type must be inferred from the ",(0,s.jsx)(t.code,{children:"ContextOf"})," type."]}),"\n",(0,s.jsxs)(t.p,{children:["You can access the context variables by using the ",(0,s.jsx)(t.code,{children:"@Context()"})," decorator within your function, which will populate the variable with an\narray of arguments."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"@On('messageCreate')\npublic onMessageCreate(@Context() [message]: ContextOf<'messageCreate'>) {\n console.log(message.content);\n}\n"})}),"\n",(0,s.jsx)(t.h2,{id:"custom-events",children:"Custom Events"}),"\n",(0,s.jsxs)(t.p,{children:["NestCord out of the box supports all the events provided by discord.js. You can also create custom events using the ",(0,s.jsx)(t.code,{children:"@CustomListenerHandler"})," and ",(0,s.jsx)(t.code,{children:"@CustomListener"})," decorators."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { CustomListener, CustomListenerHandler, BaseHandler, ContextOf } from '@globalart/nestcord';\nimport { User, UserFlagsBitField } from 'discord.js';\n\nexport type CustomUserUpdateEvents = {\n\tuserAvatarUpdate: [user: User, oldAvatar: string, newAvatar: string];\n};\n\nexport type ContextOfCustomUserUpdate = E[K];\n\n\n@Injectable()\n@CustomListener('userUpdate')\nexport class UserUpdateHandler extends BaseHandler {\n\t@CustomListenerHandler()\n\tpublic handleUserAvatarUpdate([oldUser, newUser]: ContextOf<'userUpdate'>) {\n\t\tif (oldUser.partial) return;\n\n\t\tif (oldUser.displayAvatarURL() !== newUser.displayAvatarURL()) {\n\t\t\tthis.emit(\n\t\t\t\t'userAvatarUpdate',\n\t\t\t\tnewUser,\n\t\t\t\toldUser.displayAvatarURL(),\n\t\t\t\tnewUser.displayAvatarURL()\n\t\t\t);\n\t\t}\n\t}\n}\n"})}),"\n",(0,s.jsxs)(t.p,{children:["And then you can listen to the custom event using the ",(0,s.jsx)(t.code,{children:"@On"})," decorator."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"@On('userAvatarUpdate')\npublic onUserAvatarUpdate(\n @Context() [user, oldAvatar, newAvatar]: ContextOfCustomUserUpdate<'userAvatarUpdate'>\n) {\n console.log(\n `User ${user.tag} changed their avatar from ${oldAvatar} to ${newAvatar}`\n );\n}\n"})}),"\n",(0,s.jsx)(t.p,{children:"Also supports custom events."}),"\n",(0,s.jsx)(t.h3,{id:"channel-events",children:"Channel Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildChannelPermissionsUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a channel's permission overwrite for a guild is updated."})]})})]}),"\n",(0,s.jsx)(t.h3,{id:"guild-events",children:"Guild Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildBoostLevelUp"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's boost level increases."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildBoostLevelDown"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's boost level decreases."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildBannerAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's banner is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAfkChannelAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's AFK channel is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVanityURLAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's vanity URL is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVanityURLUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's vanity URL is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVanityURLRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's vanity URL is removed."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildFeaturesUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's features are updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAcronymUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's acronym is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildOwnerUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's owner is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildPartnerAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's is partner of discord now"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildPartnerRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's is no longer partner of discord"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVerificationAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's verification level is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVerificationRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's verification level is removed."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"guild-audit-log-events",children:"Guild Audit Log Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever an entry is added to the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever an entry is updated in the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryDelete"})}),(0,s.jsx)(t.td,{children:"Emitted whenever an entry is removed from the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryWebhookCreate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a webhook is created in the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryWebhookUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a webhook is updated in the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryWebhookDelete"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a webhook is deleted in the audit log."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"guild-member-events",children:"Guild Member Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberBoost"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's boost is activated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberUnboost"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's boost is deactivated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:" guildMemberRoleAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role is added to a member."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberRoleRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role is removed from a member."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberNicknameUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's nickname is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberEntered"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member enters a guild."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberAvatarAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's avatar is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberAvatarRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's avatar is removed."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberAvatarUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's avatar is updated."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"role-update-events",children:"Role Update Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"rolePositionUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's position is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"rolePermissionsUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's permissions are updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"roleIconAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's icon is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"roleIconRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's icon is removed."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"roleIconUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's icon is updated."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"thread-update-events",children:"Thread Update Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadStateUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's state is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadNameUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's name is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadLockStateUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's lock state is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadRateLimitPerUserUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's rate limit per user is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadAutoArchiveDurationUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's auto archive duration is updated."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"message-events",children:"Message Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"messagePinned"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a message is pinned."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"messageContentEdited"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a message is updated."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"presence-events",children:"Presence Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberOffline"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member goes offline."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberOnline"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member goes online."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"user-events",children:"User Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userAvatarUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's avatar is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userUsernameUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's username is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userDiscriminatorUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's discriminator is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userFlagsUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's flags are updated."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"voice-events",children:"Voice Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelJoin"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member joins a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelLeave"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member leaves a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelSwitch"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member switches voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelMutestate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is muted or deafened in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelUnmute"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is unmuted in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelDeaf"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is deafened in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelUndeaf"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is undeafened in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceStreamingStart"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member starts streaming."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceStreamingStop"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member stops streaming."})]})]})]})]})}function o(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5710:(e,t,d)=>{d.d(t,{R:()=>i,x:()=>l});var s=d(758);const n={},r=s.createContext(n);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7d07d949.fee1fcde.js b/assets/js/7d07d949.fee1fcde.js new file mode 100644 index 0000000..a65ebd5 --- /dev/null +++ b/assets/js/7d07d949.fee1fcde.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[981],{2536:(e,t,d)=>{d.r(t),d.d(t,{assets:()=>c,contentTitle:()=>i,default:()=>o,frontMatter:()=>r,metadata:()=>l,toc:()=>a});var s=d(6070),n=d(5710);const r={id:"listeners",slug:"listeners",title:"Listeners",description:"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.",sidebar_position:3},i=void 0,l={id:"listeners",title:"Listeners",description:"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.",source:"@site/content/listeners.md",sourceDirName:".",slug:"/listeners",permalink:"/listeners",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/listeners.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{id:"listeners",slug:"listeners",title:"Listeners",description:"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Getting Started",permalink:"/start"},next:{title:"Slash Commands",permalink:"/interactions/slash-commands"}},c={},a=[{value:"Context",id:"context",level:2},{value:"Custom Events",id:"custom-events",level:2},{value:"Channel Events",id:"channel-events",level:3},{value:"Guild Events",id:"guild-events",level:3},{value:"Guild Audit Log Events",id:"guild-audit-log-events",level:4},{value:"Guild Member Events",id:"guild-member-events",level:4},{value:"Role Update Events",id:"role-update-events",level:4},{value:"Thread Update Events",id:"thread-update-events",level:4},{value:"Message Events",id:"message-events",level:3},{value:"Presence Events",id:"presence-events",level:3},{value:"User Events",id:"user-events",level:3},{value:"Voice Events",id:"voice-events",level:3}];function h(e){const t={a:"a",admonition:"admonition",br:"br",code:"code",h2:"h2",h3:"h3",h4:"h4",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,n.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["NestCord supports interacting with all ",(0,s.jsx)(t.a,{href:"https://discord.js.org/#/docs/main/stable/class/Client#Events",children:"discord events"})," via the ",(0,s.jsx)(t.code,{children:"@On"}),"\nand ",(0,s.jsx)(t.code,{children:"@Once"})," decorator.",(0,s.jsx)(t.br,{}),"\n","While the best practice is to use the more specific decorators when possible, this is useful if you wish to use features NestCord doesn't\nsupport via custom decorators, to interact with the raw requests, or to listen to all events using a decorator such as ",(0,s.jsx)(t.code,{children:"interactionCreate"}),"."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import {Injectable, Logger} from '@nestjs/common';\nimport {Once, On, Context, ContextOf} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n private readonly logger = new Logger(AppService.name);\n\n @Once('ready')\n public onReady(@Context() [client]: ContextOf<'ready'>) {\n this.logger.log(`Bot logged in as ${client.user.username}`);\n }\n\n @On('warn')\n public onWarn(@Context() [message]: ContextOf<'warn'>) {\n this.logger.warn(message);\n }\n}\n"})}),"\n",(0,s.jsx)(t.admonition,{title:"Warning",type:"caution",children:(0,s.jsxs)(t.p,{children:["If you use global filters, guards or interceptors, they will be triggered once per event!",(0,s.jsx)(t.br,{}),"\n","This means if you are replying to the message in guards, you can run into issues with duplicated responses or invalid interactions.\nHave a look at the ",(0,s.jsx)(t.code,{children:"NestCordExecutionContext.getInfo()"})," metadata to learn more about the current context."]})}),"\n",(0,s.jsx)(t.h2,{id:"context",children:"Context"}),"\n",(0,s.jsxs)(t.p,{children:["You might have noticed the ",(0,s.jsx)(t.code,{children:"@Context"})," decorator in the last snippet: This is used to inject the event context within the method.\nAs there are many type of events, its type must be inferred from the ",(0,s.jsx)(t.code,{children:"ContextOf"})," type."]}),"\n",(0,s.jsxs)(t.p,{children:["You can access the context variables by using the ",(0,s.jsx)(t.code,{children:"@Context()"})," decorator within your function, which will populate the variable with an\narray of arguments."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"@On('messageCreate')\npublic onMessageCreate(@Context() [message]: ContextOf<'messageCreate'>) {\n console.log(message.content);\n}\n"})}),"\n",(0,s.jsx)(t.h2,{id:"custom-events",children:"Custom Events"}),"\n",(0,s.jsxs)(t.p,{children:["NestCord out of the box supports all the events provided by discord.js. You can also create custom events using the ",(0,s.jsx)(t.code,{children:"@CustomListenerHandler"})," and ",(0,s.jsx)(t.code,{children:"@CustomListener"})," decorators."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { CustomListener, CustomListenerHandler, BaseHandler, ContextOf } from '@globalart/nestcord';\nimport { User, UserFlagsBitField } from 'discord.js';\n\nexport type CustomUserUpdateEvents = {\n\tuserAvatarUpdate: [user: User, oldAvatar: string, newAvatar: string];\n};\n\nexport type ContextOfCustomUserUpdate = E[K];\n\n\n@Injectable()\n@CustomListener('userUpdate')\nexport class UserUpdateHandler extends BaseHandler {\n\t@CustomListenerHandler()\n\tpublic handleUserAvatarUpdate([oldUser, newUser]: ContextOf<'userUpdate'>) {\n\t\tif (oldUser.partial) return;\n\n\t\tif (oldUser.displayAvatarURL() !== newUser.displayAvatarURL()) {\n\t\t\tthis.emit(\n\t\t\t\t'userAvatarUpdate',\n\t\t\t\tnewUser,\n\t\t\t\toldUser.displayAvatarURL(),\n\t\t\t\tnewUser.displayAvatarURL()\n\t\t\t);\n\t\t}\n\t}\n}\n"})}),"\n",(0,s.jsxs)(t.p,{children:["And then you can listen to the custom event using the ",(0,s.jsx)(t.code,{children:"@On"})," decorator."]}),"\n",(0,s.jsx)(t.pre,{children:(0,s.jsx)(t.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"@On('userAvatarUpdate')\npublic onUserAvatarUpdate(\n @Context() [user, oldAvatar, newAvatar]: ContextOfCustomUserUpdate<'userAvatarUpdate'>\n) {\n console.log(\n `User ${user.tag} changed their avatar from ${oldAvatar} to ${newAvatar}`\n );\n}\n"})}),"\n",(0,s.jsx)(t.p,{children:"Also supports custom events."}),"\n",(0,s.jsx)(t.h3,{id:"channel-events",children:"Channel Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsx)(t.tbody,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildChannelPermissionsUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a channel's permission overwrite for a guild is updated."})]})})]}),"\n",(0,s.jsx)(t.h3,{id:"guild-events",children:"Guild Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildBoostLevelUp"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's boost level increases."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildBoostLevelDown"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's boost level decreases."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildBannerAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's banner is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAfkChannelAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's AFK channel is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVanityURLAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's vanity URL is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVanityURLUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's vanity URL is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVanityURLRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's vanity URL is removed."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildFeaturesUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's features are updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAcronymUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's acronym is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildOwnerUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's owner is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildPartnerAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's is partner of discord now"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildPartnerRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's is no longer partner of discord"})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVerificationAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's verification level is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildVerificationRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a guild's verification level is removed."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"guild-audit-log-events",children:"Guild Audit Log Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever an entry is added to the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever an entry is updated in the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryDelete"})}),(0,s.jsx)(t.td,{children:"Emitted whenever an entry is removed from the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryWebhookCreate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a webhook is created in the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryWebhookUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a webhook is updated in the audit log."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildAuditLogEntryWebhookDelete"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a webhook is deleted in the audit log."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"guild-member-events",children:"Guild Member Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberBoost"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's boost is activated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberUnboost"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's boost is deactivated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:" guildMemberRoleAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role is added to a member."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberRoleRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role is removed from a member."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberNicknameUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's nickname is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberEntered"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member enters a guild."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberAvatarAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's avatar is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberAvatarRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's avatar is removed."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberAvatarUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member's avatar is updated."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"role-update-events",children:"Role Update Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"rolePositionUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's position is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"rolePermissionsUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's permissions are updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"roleIconAdd"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's icon is added."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"roleIconRemove"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's icon is removed."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"roleIconUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a role's icon is updated."})]})]})]}),"\n",(0,s.jsx)(t.h4,{id:"thread-update-events",children:"Thread Update Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadStateUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's state is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadNameUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's name is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadLockStateUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's lock state is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadRateLimitPerUserUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's rate limit per user is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"threadAutoArchiveDurationUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a thread's auto archive duration is updated."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"message-events",children:"Message Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"messagePinned"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a message is pinned."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"messageContentEdited"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a message is updated."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"presence-events",children:"Presence Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberOffline"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member goes offline."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"guildMemberOnline"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member goes online."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"user-events",children:"User Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userAvatarUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's avatar is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userUsernameUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's username is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userDiscriminatorUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's discriminator is updated."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"userFlagsUpdate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a user's flags are updated."})]})]})]}),"\n",(0,s.jsx)(t.h3,{id:"voice-events",children:"Voice Events"}),"\n",(0,s.jsxs)(t.table,{children:[(0,s.jsx)(t.thead,{children:(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.th,{children:"Event Name"}),(0,s.jsx)(t.th,{children:"Description"})]})}),(0,s.jsxs)(t.tbody,{children:[(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelJoin"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member joins a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelLeave"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member leaves a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelSwitch"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member switches voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelMutestate"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is muted or deafened in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelUnmute"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is unmuted in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelDeaf"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is deafened in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceChannelUndeaf"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member is undeafened in a voice channel."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceStreamingStart"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member starts streaming."})]}),(0,s.jsxs)(t.tr,{children:[(0,s.jsx)(t.td,{children:(0,s.jsx)(t.code,{children:"voiceStreamingStop"})}),(0,s.jsx)(t.td,{children:"Emitted whenever a member stops streaming."})]})]})]})]})}function o(e={}){const{wrapper:t}={...(0,n.R)(),...e.components};return t?(0,s.jsx)(t,{...e,children:(0,s.jsx)(h,{...e})}):h(e)}},5710:(e,t,d)=>{d.d(t,{R:()=>i,x:()=>l});var s=d(758);const n={},r=s.createContext(n);function i(e){const t=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(n):e.components||n:i(e.components),s.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7eb5a8bf.7e4e6a54.js b/assets/js/7eb5a8bf.7e4e6a54.js deleted file mode 100644 index 1690e81..0000000 --- a/assets/js/7eb5a8bf.7e4e6a54.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[539],{4829:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>c,default:()=>h,frontMatter:()=>s,metadata:()=>d,toc:()=>o});var r=t(6070),i=t(5710);const s={id:"client-providers",title:"Client Providers",sidebar_position:4},c=void 0,d={id:"techniques/client-providers",title:"Client Providers",description:"NestCord have snippets to access the client and its properties in your application.",source:"@site/content/techniques/client-providers.md",sourceDirName:"techniques",slug:"/techniques/client-providers",permalink:"/nestcord/techniques/client-providers",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/client-providers.md",tags:[],version:"current",sidebarPosition:4,frontMatter:{id:"client-providers",title:"Client Providers",sidebar_position:4},sidebar:"docsSidebar",previous:{title:"Standalone application",permalink:"/nestcord/techniques/standalone-application"},next:{title:"Contribution Guide",permalink:"/nestcord/contributing/contribution-guide"}},l={},o=[];function a(e){const n={code:"code",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,i.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.p,{children:"NestCord have snippets to access the client and its properties in your application.\nYou can inject managers and utils of discord.js client using constructor."}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Client, ChannelManager, GuildManager, UserManager, ShardClientUtil, ClientVoiceManager, WebSocketManager, REST } from 'discord.js';\n\n@Injectable()\nexport class AppService {\n public constructor(\n private readonly client: Client,\n private readonly channels: ChannelManager,\n private readonly guilds: GuildManager,\n private readonly users: UserManager,\n private readonly shard: ShardClientUtil,\n private readonly voice: ClientVoiceManager,\n private readonly ws: WebSocketManager,\n private readonly rest: REST\n ) {}\n}\n"})}),"\n",(0,r.jsxs)(n.table,{children:[(0,r.jsx)(n.thead,{children:(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.th,{children:"Class (Type to be Injected)"}),(0,r.jsx)(n.th,{children:"Client Property (Will access to)"}),(0,r.jsx)(n.th,{children:"Description"})]})}),(0,r.jsxs)(n.tbody,{children:[(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"Client"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client"})}),(0,r.jsx)(n.td,{children:"Discord.js client"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"ChannelManager"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client.channels"})}),(0,r.jsx)(n.td,{children:"Channels of client"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"GuildManager"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client.guilds"})}),(0,r.jsx)(n.td,{children:"Guilds of client"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"UserManager"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client.users"})}),(0,r.jsx)(n.td,{children:"Users of client"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"ShardClientUtil"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client.shard"})}),(0,r.jsx)(n.td,{children:"Shards utilities"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"ClientVoiceManager"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client.voice"})}),(0,r.jsx)(n.td,{children:"Voice manager"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"WebSocketManager"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client.ws"})}),(0,r.jsx)(n.td,{children:"Websocket manager"})]}),(0,r.jsxs)(n.tr,{children:[(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"REST"})}),(0,r.jsx)(n.td,{children:(0,r.jsx)(n.code,{children:"client.rest"})}),(0,r.jsx)(n.td,{children:"REST manager"})]})]})]})]})}function h(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(a,{...e})}):a(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>d});var r=t(758);const i={},s=r.createContext(i);function c(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:c(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7eb5a8bf.a6318832.js b/assets/js/7eb5a8bf.a6318832.js new file mode 100644 index 0000000..842a354 --- /dev/null +++ b/assets/js/7eb5a8bf.a6318832.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[539],{4829:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>c,default:()=>h,frontMatter:()=>s,metadata:()=>d,toc:()=>o});var i=t(6070),r=t(5710);const s={id:"client-providers",title:"Client Providers",sidebar_position:4},c=void 0,d={id:"techniques/client-providers",title:"Client Providers",description:"NestCord have snippets to access the client and its properties in your application.",source:"@site/content/techniques/client-providers.md",sourceDirName:"techniques",slug:"/techniques/client-providers",permalink:"/techniques/client-providers",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/client-providers.md",tags:[],version:"current",sidebarPosition:4,frontMatter:{id:"client-providers",title:"Client Providers",sidebar_position:4},sidebar:"docsSidebar",previous:{title:"Standalone application",permalink:"/techniques/standalone-application"},next:{title:"Contribution Guide",permalink:"/contributing/contribution-guide"}},l={},o=[];function a(e){const n={code:"code",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.p,{children:"NestCord have snippets to access the client and its properties in your application.\nYou can inject managers and utils of discord.js client using constructor."}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-typescript",metastring:'title="app.service.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Client, ChannelManager, GuildManager, UserManager, ShardClientUtil, ClientVoiceManager, WebSocketManager, REST } from 'discord.js';\n\n@Injectable()\nexport class AppService {\n public constructor(\n private readonly client: Client,\n private readonly channels: ChannelManager,\n private readonly guilds: GuildManager,\n private readonly users: UserManager,\n private readonly shard: ShardClientUtil,\n private readonly voice: ClientVoiceManager,\n private readonly ws: WebSocketManager,\n private readonly rest: REST\n ) {}\n}\n"})}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Class (Type to be Injected)"}),(0,i.jsx)(n.th,{children:"Client Property (Will access to)"}),(0,i.jsx)(n.th,{children:"Description"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"Client"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client"})}),(0,i.jsx)(n.td,{children:"Discord.js client"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"ChannelManager"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client.channels"})}),(0,i.jsx)(n.td,{children:"Channels of client"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"GuildManager"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client.guilds"})}),(0,i.jsx)(n.td,{children:"Guilds of client"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"UserManager"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client.users"})}),(0,i.jsx)(n.td,{children:"Users of client"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"ShardClientUtil"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client.shard"})}),(0,i.jsx)(n.td,{children:"Shards utilities"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"ClientVoiceManager"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client.voice"})}),(0,i.jsx)(n.td,{children:"Voice manager"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"WebSocketManager"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client.ws"})}),(0,i.jsx)(n.td,{children:"Websocket manager"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"REST"})}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"client.rest"})}),(0,i.jsx)(n.td,{children:"REST manager"})]})]})]})]})}function h(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>c,x:()=>d});var i=t(758);const r={},s=i.createContext(r);function c(e){const n=i.useContext(s);return i.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),i.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/929b52cc.92836420.js b/assets/js/929b52cc.92836420.js deleted file mode 100644 index 3183f21..0000000 --- a/assets/js/929b52cc.92836420.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[448],{6987:e=>{e.exports=JSON.parse('{"allContent":{"docusaurus-plugin-content-docs":{"default":{"loadedVersions":[{"versionName":"current","label":"Next","banner":null,"badge":false,"noIndex":false,"className":"docs-version-current","path":"/nestcord/","tagsPath":"/nestcord/tags","editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content","editUrlLocalized":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/i18n/en/docusaurus-plugin-content-docs/current","isLast":true,"routePriority":-1,"sidebarFilePath":"/home/rozmarinus/development/nestcord/docs/sidebars.js","contentPath":"/home/rozmarinus/development/nestcord/docs/content","contentPathLocalized":"/home/rozmarinus/development/nestcord/docs/i18n/en/docusaurus-plugin-content-docs/current","docs":[{"id":"contributing/code-of-conduct","title":"Code of Conduct","description":"Our Pledge","source":"@site/content/contributing/code-of-conduct.md","sourceDirName":"contributing","slug":"/contributing/code-of-conduct","permalink":"/nestcord/contributing/code-of-conduct","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/code-of-conduct.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"code-of-conduct","title":"Code of Conduct","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Contribution Guide","permalink":"/nestcord/contributing/contribution-guide"},"next":{"title":"Commit convention","permalink":"/nestcord/contributing/commit-convention"}},{"id":"contributing/commit-convention","title":"Commit convention","description":"Git Commit Message Convention","source":"@site/content/contributing/commit-convention.md","sourceDirName":"contributing","slug":"/contributing/commit-convention","permalink":"/nestcord/contributing/commit-convention","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/commit-convention.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"commit-convention","title":"Commit convention","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Code of Conduct","permalink":"/nestcord/contributing/code-of-conduct"},"next":{"title":"Funding","permalink":"/nestcord/contributing/funding"}},{"id":"contributing/contribution-guide","title":"Contribution Guide","description":"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a","source":"@site/content/contributing/contribution-guide.md","sourceDirName":"contributing","slug":"/contributing/contribution-guide","permalink":"/nestcord/contributing/contribution-guide","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/contribution-guide.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"contribution-guide","title":"Contribution Guide","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Client Providers","permalink":"/nestcord/techniques/client-providers"},"next":{"title":"Code of Conduct","permalink":"/nestcord/contributing/code-of-conduct"}},{"id":"contributing/funding","title":"Funding","description":"NestCord is an open source project with its ongoing development made possible thanks to the support by the community.","source":"@site/content/contributing/funding.md","sourceDirName":"contributing","slug":"/contributing/funding","permalink":"/nestcord/contributing/funding","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/funding.md","tags":[],"version":"current","sidebarPosition":4,"frontMatter":{"id":"funding","title":"Funding","sidebar_position":4},"sidebar":"docsSidebar","previous":{"title":"Commit convention","permalink":"/nestcord/contributing/commit-convention"}},{"id":"interactions/context-menus","title":"Context Menus","description":"User commands and message commands are now live! These commands appear on context menus for users and messages, with more to come in the future.","source":"@site/content/interactions/context-menus.md","sourceDirName":"interactions","slug":"/interactions/context-menus","permalink":"/nestcord/interactions/context-menus","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/context-menus.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"context-menus","title":"Context Menus","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Slash Commands","permalink":"/nestcord/interactions/slash-commands"},"next":{"title":"Message Components","permalink":"/nestcord/interactions/message-components"}},{"id":"interactions/message-components","title":"Message Components","description":"Message components \u2014 we\'ll call them \\"components\\" moving forward\u2014are a framework for adding interactive elements to the messages your app or bot sends. They\'re accessible, customizable, and easy to use.","source":"@site/content/interactions/message-components.md","sourceDirName":"interactions","slug":"/interactions/message-components","permalink":"/nestcord/interactions/message-components","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/message-components.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"message-components","title":"Message Components","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Context Menus","permalink":"/nestcord/interactions/context-menus"},"next":{"title":"Modals","permalink":"/nestcord/interactions/modals"}},{"id":"interactions/modals","title":"Modals","description":"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We\'ll cover how to create, show, and receive modal forms using nestcord","source":"@site/content/interactions/modals.md","sourceDirName":"interactions","slug":"/interactions/modals","permalink":"/nestcord/interactions/modals","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/modals.md","tags":[],"version":"current","sidebarPosition":4,"frontMatter":{"id":"modals","title":"Modals","sidebar_position":4},"sidebar":"docsSidebar","previous":{"title":"Message Components","permalink":"/nestcord/interactions/message-components"},"next":{"title":"Text Commands","permalink":"/nestcord/text-commands"}},{"id":"interactions/slash-commands","title":"Slash Commands","description":"Slash Commands are the new, exciting way to build and interact with bots on Discord. With Slash Commands, all you have to do is","source":"@site/content/interactions/slash-commands.md","sourceDirName":"interactions","slug":"/interactions/slash-commands","permalink":"/nestcord/interactions/slash-commands","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/slash-commands.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"slash-commands","title":"Slash Commands","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Listeners","permalink":"/nestcord/listeners"},"next":{"title":"Context Menus","permalink":"/nestcord/interactions/context-menus"}},{"id":"interceptors/defer-interceptor","title":"Defer command","description":"Interceptor added interaction.deferReply() to the beiginning of the code","source":"@site/content/interceptors/defer-interceptor.md","sourceDirName":"interceptors","slug":"/interceptors/defer-interceptor","permalink":"/nestcord/interceptors/defer-interceptor","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interceptors/defer-interceptor.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"defer-interceptor","title":"Defer command","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Text Commands","permalink":"/nestcord/text-commands"},"next":{"title":"Pagination","permalink":"/nestcord/recipes/pagination"}},{"id":"intro","title":"Introduction","description":"A module for creating Discord bots using NestJS, based on Discord.js.","source":"@site/content/intro.md","sourceDirName":".","slug":"/","permalink":"/nestcord/","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/intro.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"intro","slug":"/","title":"Introduction","description":"A module for creating Discord bots using NestJS, based on Discord.js.","sidebar_position":1},"sidebar":"docsSidebar","next":{"title":"Getting Started","permalink":"/nestcord/start"}},{"id":"listeners","title":"Listeners","description":"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.","source":"@site/content/listeners.md","sourceDirName":".","slug":"/listeners","permalink":"/nestcord/listeners","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/listeners.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"listeners","slug":"listeners","title":"Listeners","description":"Listeners are used to listen to events emitted by Discord. They are used to listen to events like `messageCreate`, `interactionCreate`, `guildMemberAdd`, etc.","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Getting Started","permalink":"/nestcord/start"},"next":{"title":"Slash Commands","permalink":"/nestcord/interactions/slash-commands"}},{"id":"recipes/localization","title":"Localization","description":"Is a lightweight localization module for NestCord. It allows you to easily localize your bot\'s","source":"@site/content/recipes/localization.md","sourceDirName":"recipes","slug":"/recipes/localization","permalink":"/nestcord/recipes/localization","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/localization.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"localization","title":"Localization","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Pagination","permalink":"/nestcord/recipes/pagination"},"next":{"title":"Stat Reporter","permalink":"/nestcord/recipes/stat-reporter"}},{"id":"recipes/pagination","title":"Pagination","description":"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and","source":"@site/content/recipes/pagination.md","sourceDirName":"recipes","slug":"/recipes/pagination","permalink":"/nestcord/recipes/pagination","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/pagination.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"pagination","title":"Pagination","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Defer command","permalink":"/nestcord/interceptors/defer-interceptor"},"next":{"title":"Localization","permalink":"/nestcord/recipes/localization"}},{"id":"recipes/stat-reporter","title":"Stat Reporter","description":"Is a lightweight stat reporter module for NestCord. This module sends data from your bot to different monitoring bot services.","source":"@site/content/recipes/stat-reporter.md","sourceDirName":"recipes","slug":"/recipes/stat-reporter","permalink":"/nestcord/recipes/stat-reporter","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/stat-reporter.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"stat-reporter","title":"Stat Reporter","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Localization","permalink":"/nestcord/recipes/localization"},"next":{"title":"Validation","permalink":"/nestcord/techniques/validation"}},{"id":"start","title":"Getting Started","description":"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!","source":"@site/content/getting-started.md","sourceDirName":".","slug":"/start","permalink":"/nestcord/start","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/getting-started.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"start","slug":"start","title":"Getting Started","description":"Are you ready to get started with nestcord? This guide will help you get started with nestcord, and will show you how to create your first bot!","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Introduction","permalink":"/nestcord/"},"next":{"title":"Listeners","permalink":"/nestcord/listeners"}},{"id":"techniques/async-configuration","title":"Async Configuration","description":"When you need to pass module options asynchronously instead of statically, use the .forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration.","source":"@site/content/techniques/async-configuration.md","sourceDirName":"techniques","slug":"/techniques/async-configuration","permalink":"/nestcord/techniques/async-configuration","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/async-configuration.md","tags":[],"version":"current","sidebarPosition":2,"frontMatter":{"id":"async-configuration","title":"Async Configuration","sidebar_position":2},"sidebar":"docsSidebar","previous":{"title":"Sharding","permalink":"/nestcord/techniques/sharding"},"next":{"title":"Standalone application","permalink":"/nestcord/techniques/standalone-application"}},{"id":"techniques/client-providers","title":"Client Providers","description":"NestCord have snippets to access the client and its properties in your application.","source":"@site/content/techniques/client-providers.md","sourceDirName":"techniques","slug":"/techniques/client-providers","permalink":"/nestcord/techniques/client-providers","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/client-providers.md","tags":[],"version":"current","sidebarPosition":4,"frontMatter":{"id":"client-providers","title":"Client Providers","sidebar_position":4},"sidebar":"docsSidebar","previous":{"title":"Standalone application","permalink":"/nestcord/techniques/standalone-application"},"next":{"title":"Contribution Guide","permalink":"/nestcord/contributing/contribution-guide"}},{"id":"techniques/sharding","title":"Sharding","description":"Discord prevents your bot application from logging in without sharding once you hit a scale of 2,500 guilds. If you are not planning to create a public bot application, then you can go ahead and ignore this section. However, if you are creating a public bot application, it would be wise to keep sharding in mind as it can increase the complexity of your application due to how a sharded process works.","source":"@site/content/techniques/sharding.md","sourceDirName":"techniques","slug":"/techniques/sharding","permalink":"/nestcord/techniques/sharding","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/sharding.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"id":"sharding","title":"Sharding","sidebar_position":1},"sidebar":"docsSidebar","previous":{"title":"Validation","permalink":"/nestcord/techniques/validation"},"next":{"title":"Async Configuration","permalink":"/nestcord/techniques/async-configuration"}},{"id":"techniques/standalone-application","title":"Standalone application","description":"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don\'t need a web server, you can remove Express.","source":"@site/content/techniques/standalone-application.md","sourceDirName":"techniques","slug":"/techniques/standalone-application","permalink":"/nestcord/techniques/standalone-application","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/standalone-application.md","tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"id":"standalone-application","title":"Standalone application","sidebar_position":3},"sidebar":"docsSidebar","previous":{"title":"Async Configuration","permalink":"/nestcord/techniques/async-configuration"},"next":{"title":"Client Providers","permalink":"/nestcord/techniques/client-providers"}},{"id":"techniques/validation","title":"Validation","description":"The ValidationPipe is a built-in pipe that can be used to validate data coming from the client. It uses class-validator package under the hood. The ValidationPipe provides a convenient approach to enforce validation rules for all incoming client payloads, where the specific rules are declared with simple annotations in DTO declarations in each module.","source":"@site/content/techniques/validation.md","sourceDirName":"techniques","slug":"/techniques/validation","permalink":"/nestcord/techniques/validation","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/validation.md","tags":[],"version":"current","sidebarPosition":0,"frontMatter":{"id":"validation","title":"Validation","sidebar_position":0},"sidebar":"docsSidebar","previous":{"title":"Stat Reporter","permalink":"/nestcord/recipes/stat-reporter"},"next":{"title":"Sharding","permalink":"/nestcord/techniques/sharding"}},{"id":"text-commands","title":"Text Commands","description":"Text commands are the most common type of command. They are used to send a message to the channel.","source":"@site/content/text-commands.md","sourceDirName":".","slug":"/text-commands","permalink":"/nestcord/text-commands","draft":false,"unlisted":false,"editUrl":"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/text-commands.md","tags":[],"version":"current","sidebarPosition":5,"frontMatter":{"id":"text-commands","slug":"text-commands","title":"Text Commands","description":"Text commands are the most common type of command. They are used to send a message to the channel.","sidebar_position":5},"sidebar":"docsSidebar","previous":{"title":"Modals","permalink":"/nestcord/interactions/modals"},"next":{"title":"Defer command","permalink":"/nestcord/interceptors/defer-interceptor"}}],"drafts":[],"sidebars":{"docsSidebar":[{"type":"doc","id":"intro"},{"type":"doc","id":"start"},{"type":"doc","id":"listeners"},{"type":"category","label":"Interactions","collapsible":true,"collapsed":false,"items":[{"type":"doc","id":"interactions/slash-commands"},{"type":"doc","id":"interactions/context-menus"},{"type":"doc","id":"interactions/message-components"},{"type":"doc","id":"interactions/modals"}]},{"type":"doc","id":"text-commands"},{"type":"category","label":"Interceptors","collapsible":true,"collapsed":true,"items":[{"type":"doc","id":"interceptors/defer-interceptor"}]},{"type":"category","label":"Recipes","collapsible":true,"collapsed":true,"items":[{"type":"doc","id":"recipes/pagination"},{"type":"doc","id":"recipes/localization"},{"type":"doc","id":"recipes/stat-reporter"}]},{"type":"category","label":"Techniques","collapsible":true,"collapsed":true,"items":[{"type":"doc","id":"techniques/validation"},{"type":"doc","id":"techniques/sharding"},{"type":"doc","id":"techniques/async-configuration"},{"type":"doc","id":"techniques/standalone-application"},{"type":"doc","id":"techniques/client-providers"}]},{"type":"category","label":"Contributing","collapsible":true,"collapsed":false,"items":[{"type":"doc","id":"contributing/contribution-guide"},{"type":"doc","id":"contributing/code-of-conduct"},{"type":"doc","id":"contributing/commit-convention"},{"type":"doc","id":"contributing/funding"}]}]}}]}},"docusaurus-plugin-debug":{},"docusaurus-plugin-sitemap":{},"docusaurus-theme-classic":{},"docusaurus-theme-search-algolia":{},"docusaurus-plugin-sass":{},"docusaurus-plugin-pwa":{},"docusaurus-bootstrap-plugin":{},"docusaurus-mdx-fallback-plugin":{}}}')}}]); \ No newline at end of file diff --git a/assets/js/9ce5ed71.6bf81289.js b/assets/js/9ce5ed71.6bf81289.js deleted file mode 100644 index ad2be0c..0000000 --- a/assets/js/9ce5ed71.6bf81289.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[810],{1409:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>m,contentTitle:()=>r,default:()=>l,frontMatter:()=>a,metadata:()=>c,toc:()=>i});var t=s(6070),o=s(5710);const a={id:"context-menus",title:"Context Menus",sidebar_position:2},r=void 0,c={id:"interactions/context-menus",title:"Context Menus",description:"User commands and message commands are now live! These commands appear on context menus for users and messages, with more to come in the future.",source:"@site/content/interactions/context-menus.md",sourceDirName:"interactions",slug:"/interactions/context-menus",permalink:"/nestcord/interactions/context-menus",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/context-menus.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"context-menus",title:"Context Menus",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Slash Commands",permalink:"/nestcord/interactions/slash-commands"},next:{title:"Message Components",permalink:"/nestcord/interactions/message-components"}},m={},i=[{value:"User Commands",id:"user-commands",level:2},{value:"Message Commands",id:"message-commands",level:2}];function d(e){const n={code:"code",h2:"h2",img:"img",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"User commands"})," and ",(0,t.jsx)(n.strong,{children:"message commands"})," are now live! These commands appear on context menus for users and messages, with more to come in the future."]}),"\n",(0,t.jsx)(n.h2,{id:"user-commands",children:"User Commands"}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"User commands"})," are application commands that appear on the context menu (right click or tap) of users. They're a great way to surface quick actions for your app that target users."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, UserCommand, UserCommandContext, TargetUser } from '@globalart/nestcord';\nimport { User } from 'discord.js';\n\n@Injectable()\nexport class AppCommands {\n @UserCommand({ name: 'Get avatar' })\n public async getUserAvatar(\n @Context() [interaction]: UserCommandContext,\n @TargetUser() user: User\n ) {\n return interaction.reply({\n embeds: [\n new MessageEmbed()\n .setTitle(`Avatar ${user.username}`)\n .setImage(user.displayAvatarURL({ size: 4096, dynamic: true }))\n ]\n });\n }\n}\n"})}),"\n",(0,t.jsx)(n.p,{children:"If all goes well, you should see something like this:"}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.img,{alt:"User Command",src:s(7625).A+"",title:"User Command",width:"451",height:"161"})}),"\n",(0,t.jsx)(n.h2,{id:"message-commands",children:"Message Commands"}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Message commands"})," are application commands that appear on the context menu (right click or tap) of messages. They're a great way to surface quick actions for your app that target messages."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, MessageCommand, MessageCommandContext, TargetMessage } from '@globalart/nestcord';\nimport { Message } from 'discord.js';\n\n@Injectable()\nexport class AppCommands {\n @MessageCommand({ name: 'Copy Message' })\n public async copyMessage(\n @Context() [interaction]: MessageCommandContext,\n @TargetMessage() message: Message\n ) {\n return interaction.reply({ content: message.content });\n }\n}\n"})}),"\n",(0,t.jsx)(n.p,{children:"If all goes well, you should see something like this:"}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.img,{alt:"Message Command",src:s(4707).A+"",title:"Message Command",width:"380",height:"124"})})]})}function l(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},4707:(e,n,s)=>{s.d(n,{A:()=>t});const t=s.p+"assets/images/context_message-74505639414ac3b590d9ea018b9f3855.png"},7625:(e,n,s)=>{s.d(n,{A:()=>t});const t=s.p+"assets/images/context_user-965f24f7e000cc826cd9e835bb855ab6.png"},5710:(e,n,s)=>{s.d(n,{R:()=>r,x:()=>c});var t=s(758);const o={},a=t.createContext(o);function r(e){const n=t.useContext(a);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9ce5ed71.d8dbf966.js b/assets/js/9ce5ed71.d8dbf966.js new file mode 100644 index 0000000..bb6d3fd --- /dev/null +++ b/assets/js/9ce5ed71.d8dbf966.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[810],{1409:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>l,frontMatter:()=>a,metadata:()=>m,toc:()=>i});var t=s(6070),o=s(5710);const a={id:"context-menus",title:"Context Menus",sidebar_position:2},r=void 0,m={id:"interactions/context-menus",title:"Context Menus",description:"User commands and message commands are now live! These commands appear on context menus for users and messages, with more to come in the future.",source:"@site/content/interactions/context-menus.md",sourceDirName:"interactions",slug:"/interactions/context-menus",permalink:"/interactions/context-menus",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/context-menus.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"context-menus",title:"Context Menus",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Slash Commands",permalink:"/interactions/slash-commands"},next:{title:"Message Components",permalink:"/interactions/message-components"}},c={},i=[{value:"User Commands",id:"user-commands",level:2},{value:"Message Commands",id:"message-commands",level:2}];function d(e){const n={code:"code",h2:"h2",img:"img",p:"p",pre:"pre",strong:"strong",...(0,o.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"User commands"})," and ",(0,t.jsx)(n.strong,{children:"message commands"})," are now live! These commands appear on context menus for users and messages, with more to come in the future."]}),"\n",(0,t.jsx)(n.h2,{id:"user-commands",children:"User Commands"}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"User commands"})," are application commands that appear on the context menu (right click or tap) of users. They're a great way to surface quick actions for your app that target users."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, UserCommand, UserCommandContext, TargetUser } from '@globalart/nestcord';\nimport { User } from 'discord.js';\n\n@Injectable()\nexport class AppCommands {\n @UserCommand({ name: 'Get avatar' })\n public async getUserAvatar(\n @Context() [interaction]: UserCommandContext,\n @TargetUser() user: User\n ) {\n return interaction.reply({\n embeds: [\n new MessageEmbed()\n .setTitle(`Avatar ${user.username}`)\n .setImage(user.displayAvatarURL({ size: 4096, dynamic: true }))\n ]\n });\n }\n}\n"})}),"\n",(0,t.jsx)(n.p,{children:"If all goes well, you should see something like this:"}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.img,{alt:"User Command",src:s(7625).A+"",title:"User Command",width:"451",height:"161"})}),"\n",(0,t.jsx)(n.h2,{id:"message-commands",children:"Message Commands"}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.strong,{children:"Message commands"})," are application commands that appear on the context menu (right click or tap) of messages. They're a great way to surface quick actions for your app that target messages."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, MessageCommand, MessageCommandContext, TargetMessage } from '@globalart/nestcord';\nimport { Message } from 'discord.js';\n\n@Injectable()\nexport class AppCommands {\n @MessageCommand({ name: 'Copy Message' })\n public async copyMessage(\n @Context() [interaction]: MessageCommandContext,\n @TargetMessage() message: Message\n ) {\n return interaction.reply({ content: message.content });\n }\n}\n"})}),"\n",(0,t.jsx)(n.p,{children:"If all goes well, you should see something like this:"}),"\n",(0,t.jsx)(n.p,{children:(0,t.jsx)(n.img,{alt:"Message Command",src:s(4707).A+"",title:"Message Command",width:"380",height:"124"})})]})}function l(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},4707:(e,n,s)=>{s.d(n,{A:()=>t});const t=s.p+"assets/images/context_message-74505639414ac3b590d9ea018b9f3855.png"},7625:(e,n,s)=>{s.d(n,{A:()=>t});const t=s.p+"assets/images/context_user-965f24f7e000cc826cd9e835bb855ab6.png"},5710:(e,n,s)=>{s.d(n,{R:()=>r,x:()=>m});var t=s(758);const o={},a=t.createContext(o);function r(e){const n=t.useContext(a);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function m(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:r(e.components),t.createElement(a.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9eb1dac9.912686f2.js b/assets/js/9eb1dac9.912686f2.js new file mode 100644 index 0000000..b29703d --- /dev/null +++ b/assets/js/9eb1dac9.912686f2.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[315],{5489:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>d,frontMatter:()=>s,metadata:()=>r,toc:()=>l});var o=n(6070),i=n(5710);const s={id:"standalone-application",title:"Standalone application",sidebar_position:3},a=void 0,r={id:"techniques/standalone-application",title:"Standalone application",description:"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don't need a web server, you can remove Express.",source:"@site/content/techniques/standalone-application.md",sourceDirName:"techniques",slug:"/techniques/standalone-application",permalink:"/techniques/standalone-application",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/standalone-application.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{id:"standalone-application",title:"Standalone application",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Async Configuration",permalink:"/techniques/async-configuration"},next:{title:"Client Providers",permalink:"/techniques/client-providers"}},c={},l=[];function p(e){const t={a:"a",admonition:"admonition",code:"code",p:"p",pre:"pre",strong:"strong",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don't need a web server, you can remove Express."}),"\n",(0,o.jsxs)(t.p,{children:["To do this, change the bootstrap function in the ",(0,o.jsx)(t.code,{children:"main.ts"})," file of your project on something like that:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="src/main.ts"',children:"import { NestFactory } from '@nestjs/core';\n\nasync function bootstrap() {\n const app = await NestFactory.createApplicationContext(AppModule);\n}\n\nbootstrap();\n"})}),"\n",(0,o.jsxs)(t.p,{children:["This initializes Nest as a ",(0,o.jsx)(t.strong,{children:"standalone application"})," (without any network listeners)."]}),"\n",(0,o.jsx)(t.p,{children:"All that remains is to remove unused dependencies:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"npm un @nestjs/platform-express @types/express\n"})}),"\n",(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsxs)(t.p,{children:["But when you run standalone application you can't use global enhancers due to the fact that they are not registered in the application context. While ",(0,o.jsx)(t.a,{href:"https://github.com/nestjs/nest/issues/9017",children:"issue"})," not resolved, you can use local enhancers instead or start your application via ",(0,o.jsx)(t.code,{children:"app.init()"})," method."]})})]})}function d(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(p,{...e})}):p(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>r});var o=n(758);const i={},s=o.createContext(i);function a(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:a(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/9eb1dac9.fd47dd9f.js b/assets/js/9eb1dac9.fd47dd9f.js deleted file mode 100644 index ced28ba..0000000 --- a/assets/js/9eb1dac9.fd47dd9f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[315],{5489:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>a,default:()=>p,frontMatter:()=>i,metadata:()=>r,toc:()=>l});var o=n(6070),s=n(5710);const i={id:"standalone-application",title:"Standalone application",sidebar_position:3},a=void 0,r={id:"techniques/standalone-application",title:"Standalone application",description:"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don't need a web server, you can remove Express.",source:"@site/content/techniques/standalone-application.md",sourceDirName:"techniques",slug:"/techniques/standalone-application",permalink:"/nestcord/techniques/standalone-application",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/techniques/standalone-application.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{id:"standalone-application",title:"Standalone application",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Async Configuration",permalink:"/nestcord/techniques/async-configuration"},next:{title:"Client Providers",permalink:"/nestcord/techniques/client-providers"}},c={},l=[];function d(e){const t={a:"a",admonition:"admonition",code:"code",p:"p",pre:"pre",strong:"strong",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:"If you initialized your application with the Nest CLI, Express framework will be installed by default along with Nest. Nest and NestCord does not require Express for work. So if you you don't need a web server, you can remove Express."}),"\n",(0,o.jsxs)(t.p,{children:["To do this, change the bootstrap function in the ",(0,o.jsx)(t.code,{children:"main.ts"})," file of your project on something like that:"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="src/main.ts"',children:"import { NestFactory } from '@nestjs/core';\n\nasync function bootstrap() {\n const app = await NestFactory.createApplicationContext(AppModule);\n}\n\nbootstrap();\n"})}),"\n",(0,o.jsxs)(t.p,{children:["This initializes Nest as a ",(0,o.jsx)(t.strong,{children:"standalone application"})," (without any network listeners)."]}),"\n",(0,o.jsx)(t.p,{children:"All that remains is to remove unused dependencies:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"npm un @nestjs/platform-express @types/express\n"})}),"\n",(0,o.jsx)(t.admonition,{type:"caution",children:(0,o.jsxs)(t.p,{children:["But when you run standalone application you can't use global enhancers due to the fact that they are not registered in the application context. While ",(0,o.jsx)(t.a,{href:"https://github.com/nestjs/nest/issues/9017",children:"issue"})," not resolved, you can use local enhancers instead or start your application via ",(0,o.jsx)(t.code,{children:"app.init()"})," method."]})})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>r});var o=n(758);const s={},i=o.createContext(s);function a(e){const t=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),o.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a4b529fe.75296125.js b/assets/js/a4b529fe.75296125.js deleted file mode 100644 index d4c91ef..0000000 --- a/assets/js/a4b529fe.75296125.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[399],{5467:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>h,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var o=n(6070),i=n(5710);const r={id:"contribution-guide",title:"Contribution Guide",sidebar_position:1},s="Contributing",c={id:"contributing/contribution-guide",title:"Contribution Guide",description:"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a",source:"@site/content/contributing/contribution-guide.md",sourceDirName:"contributing",slug:"/contributing/contribution-guide",permalink:"/nestcord/contributing/contribution-guide",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/contribution-guide.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"contribution-guide",title:"Contribution Guide",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Client Providers",permalink:"/nestcord/techniques/client-providers"},next:{title:"Code of Conduct",permalink:"/nestcord/contributing/code-of-conduct"}},d={},u=[{value:"Setup",id:"setup",level:2}];function l(e){const t={a:"a",code:"code",h1:"h1",h2:"h2",li:"li",ol:"ol",p:"p",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.h1,{id:"contributing",children:"Contributing"}),"\n",(0,o.jsx)(t.p,{children:"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a\npull request. We use ESLint to enforce a consistent coding style, so having that set up in your editor of choice\nreduces friction contributing to this project."}),"\n",(0,o.jsx)(t.h2,{id:"setup",children:"Setup"}),"\n",(0,o.jsxs)(t.p,{children:["You will need ",(0,o.jsx)(t.a,{href:"http://nodejs.org",children:"Node.js"})," ",(0,o.jsx)(t.strong,{children:"version 16+"}),", and ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/",children:"npm"}),"."]}),"\n",(0,o.jsx)(t.p,{children:"To get ready to work on the codebase, please do the following:"}),"\n",(0,o.jsxs)(t.ol,{children:["\n",(0,o.jsxs)(t.li,{children:["Fork & clone the repository. Make sure you're up-to-date with the ",(0,o.jsx)(t.strong,{children:"master"})," branch!"]}),"\n",(0,o.jsxs)(t.li,{children:["Install the dependencies using ",(0,o.jsx)(t.code,{children:"npm ci"})]}),"\n",(0,o.jsx)(t.li,{children:"Code your heart out!"}),"\n",(0,o.jsxs)(t.li,{children:["Run ",(0,o.jsx)(t.code,{children:"npm lint"})," to run ESLint and ensure changes respect our styleguide"]}),"\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://github.com/GlobalArtInc/nestcord/compare",children:"Submit a pull request"})}),"\n"]}),"\n",(0,o.jsx)(t.p,{children:"A high level overview of tools used:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/",children:"TypeScript"})," as the development language"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.a,{href:"https://eslint.org/",children:"Eslint"})," for code-style"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.a,{href:"https://prettier.io/",children:"Prettier"})," for code formatting"]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>s,x:()=>c});var o=n(758);const i={},r=o.createContext(i);function s(e){const t=o.useContext(r);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a4b529fe.8258b061.js b/assets/js/a4b529fe.8258b061.js new file mode 100644 index 0000000..a719264 --- /dev/null +++ b/assets/js/a4b529fe.8258b061.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[399],{5467:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>s,default:()=>h,frontMatter:()=>r,metadata:()=>c,toc:()=>u});var o=n(6070),i=n(5710);const r={id:"contribution-guide",title:"Contribution Guide",sidebar_position:1},s="Contributing",c={id:"contributing/contribution-guide",title:"Contribution Guide",description:"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a",source:"@site/content/contributing/contribution-guide.md",sourceDirName:"contributing",slug:"/contributing/contribution-guide",permalink:"/contributing/contribution-guide",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/contribution-guide.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"contribution-guide",title:"Contribution Guide",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Client Providers",permalink:"/techniques/client-providers"},next:{title:"Code of Conduct",permalink:"/contributing/code-of-conduct"}},d={},u=[{value:"Setup",id:"setup",level:2}];function l(e){const t={a:"a",code:"code",h1:"h1",h2:"h2",li:"li",ol:"ol",p:"p",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.h1,{id:"contributing",children:"Contributing"}),"\n",(0,o.jsx)(t.p,{children:"If you wish to contribute to the nestcord codebase or documentation, feel free to fork the repository and submit a\npull request. We use ESLint to enforce a consistent coding style, so having that set up in your editor of choice\nreduces friction contributing to this project."}),"\n",(0,o.jsx)(t.h2,{id:"setup",children:"Setup"}),"\n",(0,o.jsxs)(t.p,{children:["You will need ",(0,o.jsx)(t.a,{href:"http://nodejs.org",children:"Node.js"})," ",(0,o.jsx)(t.strong,{children:"version 16+"}),", and ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/",children:"npm"}),"."]}),"\n",(0,o.jsx)(t.p,{children:"To get ready to work on the codebase, please do the following:"}),"\n",(0,o.jsxs)(t.ol,{children:["\n",(0,o.jsxs)(t.li,{children:["Fork & clone the repository. Make sure you're up-to-date with the ",(0,o.jsx)(t.strong,{children:"master"})," branch!"]}),"\n",(0,o.jsxs)(t.li,{children:["Install the dependencies using ",(0,o.jsx)(t.code,{children:"npm ci"})]}),"\n",(0,o.jsx)(t.li,{children:"Code your heart out!"}),"\n",(0,o.jsxs)(t.li,{children:["Run ",(0,o.jsx)(t.code,{children:"npm lint"})," to run ESLint and ensure changes respect our styleguide"]}),"\n",(0,o.jsx)(t.li,{children:(0,o.jsx)(t.a,{href:"https://github.com/GlobalArtInc/nestcord/compare",children:"Submit a pull request"})}),"\n"]}),"\n",(0,o.jsx)(t.p,{children:"A high level overview of tools used:"}),"\n",(0,o.jsxs)(t.ul,{children:["\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.a,{href:"https://www.typescriptlang.org/",children:"TypeScript"})," as the development language"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.a,{href:"https://eslint.org/",children:"Eslint"})," for code-style"]}),"\n",(0,o.jsxs)(t.li,{children:[(0,o.jsx)(t.a,{href:"https://prettier.io/",children:"Prettier"})," for code formatting"]}),"\n"]})]})}function h(e={}){const{wrapper:t}={...(0,i.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(l,{...e})}):l(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>s,x:()=>c});var o=n(758);const i={},r=o.createContext(i);function s(e){const t=o.useContext(r);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function c(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),o.createElement(r.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a7f4de78.302a42b3.js b/assets/js/a7f4de78.302a42b3.js deleted file mode 100644 index b6ef9ad..0000000 --- a/assets/js/a7f4de78.302a42b3.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[597],{7897:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>m,frontMatter:()=>i,metadata:()=>r,toc:()=>d});var o=t(6070),s=t(5710);const i={id:"slash-commands",title:"Slash Commands",sidebar_position:1},l=void 0,r={id:"interactions/slash-commands",title:"Slash Commands",description:"Slash Commands are the new, exciting way to build and interact with bots on Discord. With Slash Commands, all you have to do is",source:"@site/content/interactions/slash-commands.md",sourceDirName:"interactions",slug:"/interactions/slash-commands",permalink:"/nestcord/interactions/slash-commands",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/slash-commands.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"slash-commands",title:"Slash Commands",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Listeners",permalink:"/nestcord/listeners"},next:{title:"Context Menus",permalink:"/nestcord/interactions/context-menus"}},c={},d=[{value:"Global Commands",id:"global-commands",level:2},{value:"Guild Commands",id:"guild-commands",level:2},{value:"Options",id:"options",level:2},{value:"Autocomplete",id:"autocomplete",level:2},{value:"Groups",id:"groups",level:2}];function a(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h2:"h2",img:"img",mdxAdmonitionTitle:"mdxAdmonitionTitle",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.strong,{children:"Slash Commands"})," are the new, exciting way to build and interact with bots on ",(0,o.jsx)(n.strong,{children:"Discord"}),". With Slash Commands, all you have to do is\ntype ",(0,o.jsx)(n.code,{children:"/"})," and you're ready to use your favorite bot. You can easily see all the commands a bot has, and validation and error handling help\nyou get the command right the first time."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{alt:"Slash Commands",src:t(2321).A+"",title:"Slash Commands",width:"700",height:"441"})}),"\n",(0,o.jsx)(n.h2,{id:"global-commands",children:"Global Commands"}),"\n",(0,o.jsxs)(n.admonition,{type:"tip",children:[(0,o.jsx)(n.p,{children:"Global commands are cached for one hour. New global commands will fan out slowly across all guilds and will only be guaranteed to be updated\nafter an hour. Guild commands update instantly. As such, we recommend you use guild-based commands during development and publish them to\nglobal commands when they're ready for public use."}),(0,o.jsx)(n.p,{children:(0,o.jsx)(n.a,{href:"/start#development",children:"Read more about dev-mode configuration"})})]}),"\n",(0,o.jsxs)(n.p,{children:["Create ",(0,o.jsx)(n.code,{children:"app.commands.ts"})," file and add method with ",(0,o.jsx)(n.code,{children:"SlashCommand"})," decorator."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppCommands {\n @SlashCommand({\n name: 'ping',\n description: 'Ping-Pong Command'\n })\n public async onPing(@Context() [interaction]: SlashCommandContext) {\n return interaction.reply({ content: 'Pong!' });\n }\n}\n"})}),"\n",(0,o.jsx)(n.h2,{id:"guild-commands",children:"Guild Commands"}),"\n",(0,o.jsxs)(n.p,{children:["If you want to have guild specific commands, use the ",(0,o.jsx)(n.code,{children:"guilds"})," property on the ",(0,o.jsx)(n.code,{children:"SlashCommand"})," decorator"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppCommands {\n @SlashCommand({\n name: 'ping',\n description: 'Ping-Pong Command',\n guilds: [process.env.DEV_GUILD]\n })\n public async onPing(@Context() [interaction]: SlashCommandContext) {\n return interaction.reply({ content: 'Pong!' });\n }\n}\n"})}),"\n",(0,o.jsxs)(n.blockquote,{children:["\n",(0,o.jsx)(n.p,{children:"You can use decorator on both method and class."}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,o.jsxs)(n.p,{children:["Use the option decorator to define a parameter in a slash command, let's create the ",(0,o.jsx)(n.code,{children:"LengthDto"})," class:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="length.dto.ts"',children:"import { StringOption } from '@globalart/nestcord';\n\nexport class TextDto {\n @StringOption({\n name: 'text',\n description: 'Your text',\n required: true\n })\n text: string;\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["It has only one basic properties. Thereafter we can use the newly created DTO inside the ",(0,o.jsx)(n.code,{children:"AppCommands"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, Options, SlashCommandContext } from '@globalart/nestcord';\nimport { TextDto } from './length.dto';\n\n@Injectable()\nexport class AppCommands {\n @SlashCommand({\n name: 'length',\n description: 'Get length of text'\n })\n public async onLength(@Context() [interaction]: SlashCommandContext, @Options() { text }: TextDto) {\n return interaction.reply({content: `Length of your text ${text.length}`});\n }\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"List of all built-in option decorators:"}),"\n",(0,o.jsxs)(n.table,{children:[(0,o.jsx)(n.thead,{children:(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.th,{style:{textAlign:"left"},children:"Decorator"}),(0,o.jsx)(n.th,{style:{textAlign:"left"},children:"Type"}),(0,o.jsx)(n.th,{style:{textAlign:"left"},children:"Description"})]})}),(0,o.jsxs)(n.tbody,{children:[(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"StringOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"string"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A string option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"NumberOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"number"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A number option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"IntegerOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"number"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"An integer option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"BooleanOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"boolean"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A boolean option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"UserOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"User"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A user option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"MemberOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"GuildMember"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A member option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"ChannelOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"GuildChannel"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A channel option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"RoleOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"Role"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A role option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"MentionableOption"})}),(0,o.jsxs)(n.td,{style:{textAlign:"left"},children:[(0,o.jsx)(n.code,{children:"GuildMember"})," | ",(0,o.jsx)(n.code,{children:"Role"})," | ",(0,o.jsx)(n.code,{children:"User"})]}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A mentionable option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"AttachmentOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"AttachmentOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"An attachment option"})]})]})]}),"\n",(0,o.jsx)(n.h2,{id:"autocomplete",children:"Autocomplete"}),"\n",(0,o.jsx)(n.p,{children:"To add autocomplete to your Slashcommand you will need a interceptor first. This class will intercept all requests from the user after typing in the autocomplete option field"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="anime.interceptor.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { AutocompleteInteraction } from 'discord.js';\nimport { AutocompleteInterceptor } from '@globalart/nestcord';\n\n@Injectable()\nclass AnimeAutocompleteInterceptor extends AutocompleteInterceptor {\n public transformOptions(interaction: AutocompleteInteraction) {\n const focused = interaction.options.getFocused(true);\n let choices: string[];\n\n if (focused.name === 'anime') {\n choices = ['Hunter x Hunter', 'Naruto', 'One Piece'];\n }\n\n return interaction.respond(\n choices\n .filter(choice => choice.startsWith(focused.value.toString()))\n .map(choice => ({ name: choice, value: choice }))\n );\n }\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["You'll then have to add ",(0,o.jsx)(n.code,{children:"autocomplete: true"})," to your options class:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="anime.dto.ts"',children:"import { StringOption } from '@globalart/nestcord';\n\nexport class AnimeDto {\n @StringOption({\n name: 'anime',\n description: 'The anime to look up',\n autocomplete: true,\n required: true\n })\n anime: string;\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"And last but not least, apply the interceptor to your slash command"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="anime-commands.service.ts"',children:"import { Injectable, UseInterceptors } from '@nestjs/common';\nimport { Context, SlashCommand, Options, SlashCommandContext } from '@globalart/nestcord';\nimport { AnimeDto } from '/anime.dto';\nimport { AnimeAutocompleteInterceptor } from './anime.interceptor';\n\n@Injectable()\nexport class AnimeCommands {\n @UseInterceptors(AnimeAutocompleteInterceptor)\n @SlashCommand({\n name: 'anime',\n description: 'Lookup information about an anime'\n })\n public async onSearch(@Context() [interaction]: SlashCommandContext, @Options() { anime }: AnimeDto) {\n return interaction.reply({content: `I found the anime ${anime}`});\n }\n}\n"})}),"\n",(0,o.jsx)(n.h2,{id:"groups",children:"Groups"}),"\n",(0,o.jsxs)(n.admonition,{type:"tip",children:[(0,o.jsx)(n.mdxAdmonitionTitle,{children:(0,o.jsx)(n.strong,{children:"TIP"})}),(0,o.jsx)(n.p,{children:"For those developers looking to make more organized and complex groups of commands, look no further than subgroups and groups."})]}),"\n",(0,o.jsxs)(n.p,{children:["Use ",(0,o.jsx)(n.code,{children:"SlashGroup"})," decorators on class-level ",(0,o.jsx)(n.code,{children:"(Group)"})," and method-level ",(0,o.jsx)(n.code,{children:"(SubGroup)"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="utils-commands.service.ts"',children:"import {createCommandGroupDecorator, Subcommand} from '@globalart/nestcord';\n\nexport const UtilsCommandDecorator = createCommandGroupDecorator({\n name: 'utils',\n description: 'Utils group',\n});\n\n@UtilsCommandDecorator()\nexport class UtilsCommands {\n @Subcommand({\n name: 'ping',\n description: 'Ping-pong command'\n })\n public async onPing(...) {\n ...\n }\n}\n\n@UtilsCommandDecorator({\n name: 'string',\n descriptionn: 'String utility commands'\n})\nexport class UtilsStringCommands {\n @Subcommand({\n name: 'length',\n description: 'String length command'\n })\n public async onLength(...) {\n ...\n }\n}\n\n\n"})}),"\n",(0,o.jsxs)(n.p,{children:["After the registration commands, the bot will process ",(0,o.jsx)(n.code,{children:"/utils ping"})," and ",(0,o.jsx)(n.code,{children:"/utils string length"})," commands, like here:"]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{alt:"Commands",src:t(2172).A+"",width:"273",height:"146"})})]})}function m(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},2172:(e,n,t)=>{t.d(n,{A:()=>o});const o=t.p+"assets/images/slash_command_example-12de9d8060483488ad5be48eb50f1ebf.png"},2321:(e,n,t)=>{t.d(n,{A:()=>o});const o=t.p+"assets/images/slash_command_menu-9ebf84e04a36a479bf3472be8f8f138c.png"},5710:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var o=t(758);const s={},i=o.createContext(s);function l(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/a7f4de78.711ca252.js b/assets/js/a7f4de78.711ca252.js new file mode 100644 index 0000000..e87f3a8 --- /dev/null +++ b/assets/js/a7f4de78.711ca252.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[597],{7897:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>m,frontMatter:()=>i,metadata:()=>r,toc:()=>d});var o=t(6070),s=t(5710);const i={id:"slash-commands",title:"Slash Commands",sidebar_position:1},l=void 0,r={id:"interactions/slash-commands",title:"Slash Commands",description:"Slash Commands are the new, exciting way to build and interact with bots on Discord. With Slash Commands, all you have to do is",source:"@site/content/interactions/slash-commands.md",sourceDirName:"interactions",slug:"/interactions/slash-commands",permalink:"/interactions/slash-commands",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/slash-commands.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"slash-commands",title:"Slash Commands",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Listeners",permalink:"/listeners"},next:{title:"Context Menus",permalink:"/interactions/context-menus"}},c={},d=[{value:"Global Commands",id:"global-commands",level:2},{value:"Guild Commands",id:"guild-commands",level:2},{value:"Options",id:"options",level:2},{value:"Autocomplete",id:"autocomplete",level:2},{value:"Groups",id:"groups",level:2}];function a(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h2:"h2",img:"img",mdxAdmonitionTitle:"mdxAdmonitionTitle",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(n.p,{children:[(0,o.jsx)(n.strong,{children:"Slash Commands"})," are the new, exciting way to build and interact with bots on ",(0,o.jsx)(n.strong,{children:"Discord"}),". With Slash Commands, all you have to do is\ntype ",(0,o.jsx)(n.code,{children:"/"})," and you're ready to use your favorite bot. You can easily see all the commands a bot has, and validation and error handling help\nyou get the command right the first time."]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{alt:"Slash Commands",src:t(2321).A+"",title:"Slash Commands",width:"700",height:"441"})}),"\n",(0,o.jsx)(n.h2,{id:"global-commands",children:"Global Commands"}),"\n",(0,o.jsxs)(n.admonition,{type:"tip",children:[(0,o.jsx)(n.p,{children:"Global commands are cached for one hour. New global commands will fan out slowly across all guilds and will only be guaranteed to be updated\nafter an hour. Guild commands update instantly. As such, we recommend you use guild-based commands during development and publish them to\nglobal commands when they're ready for public use."}),(0,o.jsx)(n.p,{children:(0,o.jsx)(n.a,{href:"/start#development",children:"Read more about dev-mode configuration"})})]}),"\n",(0,o.jsxs)(n.p,{children:["Create ",(0,o.jsx)(n.code,{children:"app.commands.ts"})," file and add method with ",(0,o.jsx)(n.code,{children:"SlashCommand"})," decorator."]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppCommands {\n @SlashCommand({\n name: 'ping',\n description: 'Ping-Pong Command'\n })\n public async onPing(@Context() [interaction]: SlashCommandContext) {\n return interaction.reply({ content: 'Pong!' });\n }\n}\n"})}),"\n",(0,o.jsx)(n.h2,{id:"guild-commands",children:"Guild Commands"}),"\n",(0,o.jsxs)(n.p,{children:["If you want to have guild specific commands, use the ",(0,o.jsx)(n.code,{children:"guilds"})," property on the ",(0,o.jsx)(n.code,{children:"SlashCommand"})," decorator"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppCommands {\n @SlashCommand({\n name: 'ping',\n description: 'Ping-Pong Command',\n guilds: [process.env.DEV_GUILD]\n })\n public async onPing(@Context() [interaction]: SlashCommandContext) {\n return interaction.reply({ content: 'Pong!' });\n }\n}\n"})}),"\n",(0,o.jsxs)(n.blockquote,{children:["\n",(0,o.jsx)(n.p,{children:"You can use decorator on both method and class."}),"\n"]}),"\n",(0,o.jsx)(n.h2,{id:"options",children:"Options"}),"\n",(0,o.jsxs)(n.p,{children:["Use the option decorator to define a parameter in a slash command, let's create the ",(0,o.jsx)(n.code,{children:"LengthDto"})," class:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="length.dto.ts"',children:"import { StringOption } from '@globalart/nestcord';\n\nexport class TextDto {\n @StringOption({\n name: 'text',\n description: 'Your text',\n required: true\n })\n text: string;\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["It has only one basic properties. Thereafter we can use the newly created DTO inside the ",(0,o.jsx)(n.code,{children:"AppCommands"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="app.commands.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, SlashCommand, Options, SlashCommandContext } from '@globalart/nestcord';\nimport { TextDto } from './length.dto';\n\n@Injectable()\nexport class AppCommands {\n @SlashCommand({\n name: 'length',\n description: 'Get length of text'\n })\n public async onLength(@Context() [interaction]: SlashCommandContext, @Options() { text }: TextDto) {\n return interaction.reply({content: `Length of your text ${text.length}`});\n }\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"List of all built-in option decorators:"}),"\n",(0,o.jsxs)(n.table,{children:[(0,o.jsx)(n.thead,{children:(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.th,{style:{textAlign:"left"},children:"Decorator"}),(0,o.jsx)(n.th,{style:{textAlign:"left"},children:"Type"}),(0,o.jsx)(n.th,{style:{textAlign:"left"},children:"Description"})]})}),(0,o.jsxs)(n.tbody,{children:[(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"StringOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"string"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A string option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"NumberOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"number"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A number option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"IntegerOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"number"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"An integer option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"BooleanOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"boolean"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A boolean option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"UserOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"User"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A user option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"MemberOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"GuildMember"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A member option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"ChannelOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"GuildChannel"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A channel option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"RoleOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"Role"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A role option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"MentionableOption"})}),(0,o.jsxs)(n.td,{style:{textAlign:"left"},children:[(0,o.jsx)(n.code,{children:"GuildMember"})," | ",(0,o.jsx)(n.code,{children:"Role"})," | ",(0,o.jsx)(n.code,{children:"User"})]}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"A mentionable option"})]}),(0,o.jsxs)(n.tr,{children:[(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"AttachmentOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:(0,o.jsx)(n.code,{children:"AttachmentOption"})}),(0,o.jsx)(n.td,{style:{textAlign:"left"},children:"An attachment option"})]})]})]}),"\n",(0,o.jsx)(n.h2,{id:"autocomplete",children:"Autocomplete"}),"\n",(0,o.jsx)(n.p,{children:"To add autocomplete to your Slashcommand you will need a interceptor first. This class will intercept all requests from the user after typing in the autocomplete option field"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="anime.interceptor.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { AutocompleteInteraction } from 'discord.js';\nimport { AutocompleteInterceptor } from '@globalart/nestcord';\n\n@Injectable()\nclass AnimeAutocompleteInterceptor extends AutocompleteInterceptor {\n public transformOptions(interaction: AutocompleteInteraction) {\n const focused = interaction.options.getFocused(true);\n let choices: string[];\n\n if (focused.name === 'anime') {\n choices = ['Hunter x Hunter', 'Naruto', 'One Piece'];\n }\n\n return interaction.respond(\n choices\n .filter(choice => choice.startsWith(focused.value.toString()))\n .map(choice => ({ name: choice, value: choice }))\n );\n }\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["You'll then have to add ",(0,o.jsx)(n.code,{children:"autocomplete: true"})," to your options class:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="anime.dto.ts"',children:"import { StringOption } from '@globalart/nestcord';\n\nexport class AnimeDto {\n @StringOption({\n name: 'anime',\n description: 'The anime to look up',\n autocomplete: true,\n required: true\n })\n anime: string;\n}\n"})}),"\n",(0,o.jsx)(n.p,{children:"And last but not least, apply the interceptor to your slash command"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="anime-commands.service.ts"',children:"import { Injectable, UseInterceptors } from '@nestjs/common';\nimport { Context, SlashCommand, Options, SlashCommandContext } from '@globalart/nestcord';\nimport { AnimeDto } from '/anime.dto';\nimport { AnimeAutocompleteInterceptor } from './anime.interceptor';\n\n@Injectable()\nexport class AnimeCommands {\n @UseInterceptors(AnimeAutocompleteInterceptor)\n @SlashCommand({\n name: 'anime',\n description: 'Lookup information about an anime'\n })\n public async onSearch(@Context() [interaction]: SlashCommandContext, @Options() { anime }: AnimeDto) {\n return interaction.reply({content: `I found the anime ${anime}`});\n }\n}\n"})}),"\n",(0,o.jsx)(n.h2,{id:"groups",children:"Groups"}),"\n",(0,o.jsxs)(n.admonition,{type:"tip",children:[(0,o.jsx)(n.mdxAdmonitionTitle,{children:(0,o.jsx)(n.strong,{children:"TIP"})}),(0,o.jsx)(n.p,{children:"For those developers looking to make more organized and complex groups of commands, look no further than subgroups and groups."})]}),"\n",(0,o.jsxs)(n.p,{children:["Use ",(0,o.jsx)(n.code,{children:"SlashGroup"})," decorators on class-level ",(0,o.jsx)(n.code,{children:"(Group)"})," and method-level ",(0,o.jsx)(n.code,{children:"(SubGroup)"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",metastring:'title="utils-commands.service.ts"',children:"import {createCommandGroupDecorator, Subcommand} from '@globalart/nestcord';\n\nexport const UtilsCommandDecorator = createCommandGroupDecorator({\n name: 'utils',\n description: 'Utils group',\n});\n\n@UtilsCommandDecorator()\nexport class UtilsCommands {\n @Subcommand({\n name: 'ping',\n description: 'Ping-pong command'\n })\n public async onPing(...) {\n ...\n }\n}\n\n@UtilsCommandDecorator({\n name: 'string',\n descriptionn: 'String utility commands'\n})\nexport class UtilsStringCommands {\n @Subcommand({\n name: 'length',\n description: 'String length command'\n })\n public async onLength(...) {\n ...\n }\n}\n\n\n"})}),"\n",(0,o.jsxs)(n.p,{children:["After the registration commands, the bot will process ",(0,o.jsx)(n.code,{children:"/utils ping"})," and ",(0,o.jsx)(n.code,{children:"/utils string length"})," commands, like here:"]}),"\n",(0,o.jsx)(n.p,{children:(0,o.jsx)(n.img,{alt:"Commands",src:t(2172).A+"",width:"273",height:"146"})})]})}function m(e={}){const{wrapper:n}={...(0,s.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},2172:(e,n,t)=>{t.d(n,{A:()=>o});const o=t.p+"assets/images/slash_command_example-12de9d8060483488ad5be48eb50f1ebf.png"},2321:(e,n,t)=>{t.d(n,{A:()=>o});const o=t.p+"assets/images/slash_command_menu-9ebf84e04a36a479bf3472be8f8f138c.png"},5710:(e,n,t)=>{t.d(n,{R:()=>l,x:()=>r});var o=t(758);const s={},i=o.createContext(s);function l(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/bf4f2dd0.02dab1c5.js b/assets/js/bf4f2dd0.02dab1c5.js deleted file mode 100644 index 89d592a..0000000 --- a/assets/js/bf4f2dd0.02dab1c5.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[179],{3117:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>s,toc:()=>l});var o=t(6070),a=t(5710);const i={id:"pagination",title:"Pagination",sidebar_position:1},r=void 0,s={id:"recipes/pagination",title:"Pagination",description:"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and",source:"@site/content/recipes/pagination.md",sourceDirName:"recipes",slug:"/recipes/pagination",permalink:"/nestcord/recipes/pagination",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/pagination.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"pagination",title:"Pagination",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Defer command",permalink:"/nestcord/interceptors/defer-interceptor"},next:{title:"Localization",permalink:"/nestcord/recipes/localization"}},c={},l=[{value:"Usage",id:"usage",level:2}];function d(e){const n={code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.p,{children:"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and\nmanageable way. When dealing with substantial volumes of data, such as search results, articles, or product listings, presenting it all at\nonce can overwhelm users and lead to a poor user experience. Pagination allows you to divide the information into smaller, organized chunks,\nenhancing user engagement and ease of navigation. This module allows you to create a pagination with a few lines of code."}),"\n",(0,o.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,o.jsxs)(n.p,{children:["Once the installation process is complete, we can import the ",(0,o.jsx)(n.code,{children:"NestCordPaginationModule"})," with your ",(0,o.jsx)(n.code,{children:"NestCordModule"})," into the root ",(0,o.jsx)(n.code,{children:"AppModule"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { NestCordPaginationModule } from '@globalart/nestcord';\nimport { AppService } from './app.service';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: 'DISCORD_BOT_TOKEN',\n intents: ['Guilds', 'GuildMessages', 'DirectMessages']\n }),\n NestCordPaginationModule.forRoot({\n // Change your buttons appearance\n buttons: {},\n // Add buttons for skip to first and last page\n allowSkip: true,\n // Add buttons for search page\n allowTraversal: true\n })\n ],\n providers: [AppService]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Then, we can inject the ",(0,o.jsx)(n.code,{children:"PaginationService"})," into our service and register a pagination handler:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",children:"import { OnModuleInit, Injectable } from '@nestjs/common';\nimport { NestCordPaginationService, PageBuilder } from '@globalart/nestcord/pagination';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService implements OnModuleInit {\n public constructor(private readonly paginationService: NestCordPaginationService) {\n }\n\n public onModuleInit(): void {\n return this.paginationService.register(builder =>\n builder\n // Required, need for search your builder\n .setCustomId('test')\n // First way to set pages\n .setPages([\n new PageBuilder().setContent('Page 1'),\n new PageBuilder().setContent('Page 2'),\n new PageBuilder().setContent('Page 3'),\n new PageBuilder().setContent('Page 4'),\n new PageBuilder().setContent('Page 5')\n ])\n // Second way, you can manually set pages using `setPages` method\n .setPagesFactory(page => new PageBuilder().setContent(`Page ${page}`))\n // Optional, only if you want to use pages factory\n .setMaxPages(5)\n );\n }\n\n @SlashCommand({ name: 'pagination', description: 'Test pagination' })\n public async onPagination(@Context() [interaction]: SlashCommandContext) {\n const pagination = this.paginationService.get('test');\n const page = await pagination.build();\n\n return interaction.reply(page);\n }\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Congratulations! You have successfully created your first pagination!\nJust use ",(0,o.jsx)(n.code,{children:"pagination"})," command and you will see your pagination!"]})]})}function p(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>s});var o=t(758);const a={},i=o.createContext(a);function r(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/bf4f2dd0.7f5eebad.js b/assets/js/bf4f2dd0.7f5eebad.js new file mode 100644 index 0000000..b024ce1 --- /dev/null +++ b/assets/js/bf4f2dd0.7f5eebad.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[179],{3117:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>r,default:()=>p,frontMatter:()=>i,metadata:()=>s,toc:()=>l});var o=t(6070),a=t(5710);const i={id:"pagination",title:"Pagination",sidebar_position:1},r=void 0,s={id:"recipes/pagination",title:"Pagination",description:"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and",source:"@site/content/recipes/pagination.md",sourceDirName:"recipes",slug:"/recipes/pagination",permalink:"/recipes/pagination",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/pagination.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"pagination",title:"Pagination",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Defer command",permalink:"/interceptors/defer-interceptor"},next:{title:"Localization",permalink:"/recipes/localization"}},c={},l=[{value:"Usage",id:"usage",level:2}];function d(e){const n={code:"code",h2:"h2",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.p,{children:"Certainly! Pagination is a useful technique employed in user interfaces to present large amounts of information in a structured and\nmanageable way. When dealing with substantial volumes of data, such as search results, articles, or product listings, presenting it all at\nonce can overwhelm users and lead to a poor user experience. Pagination allows you to divide the information into smaller, organized chunks,\nenhancing user engagement and ease of navigation. This module allows you to create a pagination with a few lines of code."}),"\n",(0,o.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,o.jsxs)(n.p,{children:["Once the installation process is complete, we can import the ",(0,o.jsx)(n.code,{children:"NestCordPaginationModule"})," with your ",(0,o.jsx)(n.code,{children:"NestCordModule"})," into the root ",(0,o.jsx)(n.code,{children:"AppModule"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { NestCordPaginationModule } from '@globalart/nestcord';\nimport { AppService } from './app.service';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: 'DISCORD_BOT_TOKEN',\n intents: ['Guilds', 'GuildMessages', 'DirectMessages']\n }),\n NestCordPaginationModule.forRoot({\n // Change your buttons appearance\n buttons: {},\n // Add buttons for skip to first and last page\n allowSkip: true,\n // Add buttons for search page\n allowTraversal: true\n })\n ],\n providers: [AppService]\n})\nexport class AppModule {}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Then, we can inject the ",(0,o.jsx)(n.code,{children:"PaginationService"})," into our service and register a pagination handler:"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-typescript",children:"import { OnModuleInit, Injectable } from '@nestjs/common';\nimport { NestCordPaginationService, PageBuilder } from '@globalart/nestcord/pagination';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService implements OnModuleInit {\n public constructor(private readonly paginationService: NestCordPaginationService) {\n }\n\n public onModuleInit(): void {\n return this.paginationService.register(builder =>\n builder\n // Required, need for search your builder\n .setCustomId('test')\n // First way to set pages\n .setPages([\n new PageBuilder().setContent('Page 1'),\n new PageBuilder().setContent('Page 2'),\n new PageBuilder().setContent('Page 3'),\n new PageBuilder().setContent('Page 4'),\n new PageBuilder().setContent('Page 5')\n ])\n // Second way, you can manually set pages using `setPages` method\n .setPagesFactory(page => new PageBuilder().setContent(`Page ${page}`))\n // Optional, only if you want to use pages factory\n .setMaxPages(5)\n );\n }\n\n @SlashCommand({ name: 'pagination', description: 'Test pagination' })\n public async onPagination(@Context() [interaction]: SlashCommandContext) {\n const pagination = this.paginationService.get('test');\n const page = await pagination.build();\n\n return interaction.reply(page);\n }\n}\n"})}),"\n",(0,o.jsxs)(n.p,{children:["Congratulations! You have successfully created your first pagination!\nJust use ",(0,o.jsx)(n.code,{children:"pagination"})," command and you will see your pagination!"]})]})}function p(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,o.jsx)(n,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},5710:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>s});var o=t(758);const a={},i=o.createContext(a);function r(e){const n=o.useContext(i);return o.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function s(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),o.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d291a071.47f75ee6.js b/assets/js/d291a071.47f75ee6.js deleted file mode 100644 index 4803798..0000000 --- a/assets/js/d291a071.47f75ee6.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[504],{788:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>l,frontMatter:()=>c,metadata:()=>s,toc:()=>a});var r=n(6070),o=n(5710);const c={id:"defer-interceptor",title:"Defer command",sidebar_position:1},i=void 0,s={id:"interceptors/defer-interceptor",title:"Defer command",description:"Interceptor added interaction.deferReply() to the beiginning of the code",source:"@site/content/interceptors/defer-interceptor.md",sourceDirName:"interceptors",slug:"/interceptors/defer-interceptor",permalink:"/nestcord/interceptors/defer-interceptor",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interceptors/defer-interceptor.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"defer-interceptor",title:"Defer command",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Text Commands",permalink:"/nestcord/text-commands"},next:{title:"Pagination",permalink:"/nestcord/recipes/pagination"}},d={},a=[{value:"Usage",id:"usage",level:2}];function p(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Interceptor added ",(0,r.jsx)(t.code,{children:"interaction.deferReply()"})," to the beiginning of the code"]}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",children:"import {\n Context,\n SlashCommand,\n SlashCommandContext,\n DeferCommandInterceptor,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @UseInterceptors(DeferCommandInterceptor)\n @SlashCommand({\n name: 'ping',\n description: 'pong',\n })\n async execute(@Context() [interaction]: SlashCommandContext) {\n setTimeout(() => interaction.followUp({ content: 'Pong!' }), 5000);\n }\n}\n\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>i,x:()=>s});var r=n(758);const o={},c=r.createContext(o);function i(e){const t=r.useContext(c);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:i(e.components),r.createElement(c.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d291a071.b80834f1.js b/assets/js/d291a071.b80834f1.js new file mode 100644 index 0000000..88a81ab --- /dev/null +++ b/assets/js/d291a071.b80834f1.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[504],{788:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>c,default:()=>l,frontMatter:()=>i,metadata:()=>s,toc:()=>d});var r=n(6070),o=n(5710);const i={id:"defer-interceptor",title:"Defer command",sidebar_position:1},c=void 0,s={id:"interceptors/defer-interceptor",title:"Defer command",description:"Interceptor added interaction.deferReply() to the beiginning of the code",source:"@site/content/interceptors/defer-interceptor.md",sourceDirName:"interceptors",slug:"/interceptors/defer-interceptor",permalink:"/interceptors/defer-interceptor",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interceptors/defer-interceptor.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"defer-interceptor",title:"Defer command",sidebar_position:1},sidebar:"docsSidebar",previous:{title:"Text Commands",permalink:"/text-commands"},next:{title:"Pagination",permalink:"/recipes/pagination"}},a={},d=[{value:"Usage",id:"usage",level:2}];function p(e){const t={code:"code",h2:"h2",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(t.p,{children:["Interceptor added ",(0,r.jsx)(t.code,{children:"interaction.deferReply()"})," to the beiginning of the code"]}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",children:"import {\n Context,\n SlashCommand,\n SlashCommandContext,\n DeferCommandInterceptor,\n} from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService {\n @UseInterceptors(DeferCommandInterceptor)\n @SlashCommand({\n name: 'ping',\n description: 'pong',\n })\n async execute(@Context() [interaction]: SlashCommandContext) {\n setTimeout(() => interaction.followUp({ content: 'Pong!' }), 5000);\n }\n}\n\n"})})]})}function l(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>c,x:()=>s});var r=n(758);const o={},i=r.createContext(o);function c(e){const t=r.useContext(i);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function s(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:c(e.components),r.createElement(i.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d347213b.0545900f.js b/assets/js/d347213b.0545900f.js new file mode 100644 index 0000000..1c763f6 --- /dev/null +++ b/assets/js/d347213b.0545900f.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[467],{792:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>r,contentTitle:()=>s,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>c});var t=o(6070),a=o(5710);const i={id:"localization",title:"Localization",sidebar_position:2},s=void 0,l={id:"recipes/localization",title:"Localization",description:"Is a lightweight localization module for NestCord. It allows you to easily localize your bot's",source:"@site/content/recipes/localization.md",sourceDirName:"recipes",slug:"/recipes/localization",permalink:"/recipes/localization",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/localization.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"localization",title:"Localization",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Pagination",permalink:"/recipes/pagination"},next:{title:"Stat Reporter",permalink:"/recipes/stat-reporter"}},r={},c=[{value:"Usage",id:"usage",level:2},{value:"Adapters",id:"adapters",level:2},{value:"Custom Adapters",id:"custom-adapters",level:4},{value:"Resolvers",id:"resolvers",level:2},{value:"Custom Resolvers",id:"custom-resolvers",level:4},{value:"Localization",id:"localization",level:2},{value:"Setting up localized commands",id:"setting-up-localized-commands",level:4}];function d(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",h4:"h4",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,a.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["Is a lightweight localization module for ",(0,t.jsx)(n.a,{href:"https://nestcord.globalart.dev/",children:"NestCord"}),". It allows you to easily localize your bot's\ncommands and messages. The module provides a simple API for managing locales and translations, as well as a powerful localization adapter\nsystem."]}),"\n",(0,t.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,t.jsxs)(n.p,{children:["Once the installation process is complete, we can import the ",(0,t.jsx)(n.code,{children:"NestCordLocalizationModule"})," with your ",(0,t.jsx)(n.code,{children:"NestCordModule"})," into the root ",(0,t.jsx)(n.code,{children:"AppModule"}),":"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { NestCordLocalizationModule, DefaultLocalizationAdapter, UserResolver } from '@globalart/nestcord';\nimport { AppService } from './app.service';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: process.env.DISCORD_TOKEN,\n intents: [\n IntentsBitField.Flags.Guilds,\n IntentsBitField.Flags.DirectMessages,\n IntentsBitField.Flags.GuildMembers,\n IntentsBitField.Flags.GuildMessages,\n IntentsBitField.Flags.MessageContent\n ],\n prefix: '!',\n development: [process.env.DISCORD_TEST_GUILD]\n }),\n NestCordLocalizationModule.forRoot({\n resolvers: UserResolver,\n // Also you can provide class for support injection by @Inject\n adapter: new DefaultLocalizationAdapter({\n fallbackLocale: 'en-US',\n locales: {\n 'en-US': {\n 'commands.ping.name': 'ping',\n 'commands.ping.description': 'Pong!'\n },\n ru: {\n 'commands.ping.name': '\u043f\u0438\u043d\u0433',\n 'commands.ping.description': '\u041f\u043e\u043d\u0433!'\n }\n }\n })\n })\n ],\n providers: [AppService]\n})\nexport class AppModule {\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"adapters",children:"Adapters"}),"\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"DefaultLocalizationAdapter"})," is a simple adapter that allows you to provide a map of locales and translations."]}),"\n",(0,t.jsxs)(n.p,{children:["Also you can use the ",(0,t.jsx)(n.code,{children:"NestedLocalizationAdapter"})," that allows you to organize translation keys into objects"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestCordLocalizationModule, NestedLocalizationAdapter, UserResolver } from '@globalart/nestcord/localization';\n\nNestCordLocalizationModule.forRoot({\n resolvers: UserResolver,\n adapter: new NestedLocalizationAdapter({\n fallbackLocale: 'en-US',\n locales: {\n 'en-US': {\n 'commands': {\n 'ping': {\n 'name': 'ping',\n 'description': 'Pong!'\n }\n }\n },\n ru: {\n 'commands': {\n 'ping': {\n 'name': '\u043f\u0438\u043d\u0433',\n 'description': '\u041f\u043e\u043d\u0433!'\n }\n }\n }\n }\n })\n})\n\n"})}),"\n",(0,t.jsx)(n.admonition,{type:"info",children:(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"DefaultLocalizationAdapter"})," and ",(0,t.jsx)(n.code,{children:"NestedLocalizationAdapter"})," can translate your localization strings and placeholders (e.g ",(0,t.jsx)(n.code,{children:"{{username}}"}),")"]})}),"\n",(0,t.jsx)(n.h4,{id:"custom-adapters",children:"Custom Adapters"}),"\n",(0,t.jsxs)(n.p,{children:["Also, you can create your own localization adapter. Just implement the ",(0,t.jsx)(n.code,{children:"BaseLocalizationAdapter"})," interface:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { BaseLocalizationAdapter } from '@globalart/nestcord/localization';\n\ninterface CustomLocalizationOptions {\n fallbackLocale: string;\n locales: Record>;\n}\n\nexport class CustomLocalizationAdapter extends BaseLocalizationAdapter {\n public getTranslation(key: string, locale: string, ...args: any[]): string {\n return `${key} by ${locale}`;\n }\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"resolvers",children:"Resolvers"}),"\n",(0,t.jsxs)(n.p,{children:["Resolvers are used to get the locale for translation. By default, NestCord provides two resolvers: ",(0,t.jsx)(n.code,{children:"UserResolver"})," and ",(0,t.jsx)(n.code,{children:"GuildResolver"}),"."]}),"\n",(0,t.jsxs)(n.table,{children:[(0,t.jsx)(n.thead,{children:(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.th,{children:"Resolver"}),(0,t.jsx)(n.th,{children:"Description"})]})}),(0,t.jsxs)(n.tbody,{children:[(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:"UserResolver"}),(0,t.jsxs)(n.td,{children:["Gets the locale from the user's locale property (",(0,t.jsx)(n.code,{children:"interaction.locale"}),")"]})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:"GuildResolver"}),(0,t.jsxs)(n.td,{children:["Gets the locale from the guild's locale property (",(0,t.jsx)(n.code,{children:"interaction.guildLocale"}),")"]})]})]})]}),"\n",(0,t.jsx)(n.h4,{id:"custom-resolvers",children:"Custom Resolvers"}),"\n",(0,t.jsxs)(n.p,{children:["Also, you can create your own Resolver. Just implement the ",(0,t.jsx)(n.code,{children:"LocaleResolver"})," interface:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { CommandContext, LocaleResolver } from '@globalart/nestcord';\nimport { ExecutionContext, Injectable } from '@nestjs/common';\nimport { NestCordExecutionContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class GuildResolver implements LocaleResolver {\n resolve(context: ExecutionContext): string | string[] | undefined {\n const nestcordContext = NestCordExecutionContext.create(context);\n const [interaction] = nestcordContext.getContext();\n\n return interaction.guildLocale;\n }\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"localization",children:"Localization"}),"\n",(0,t.jsxs)(n.p,{children:["We can inject the ",(0,t.jsx)(n.code,{children:"LOCALIZATION_ADAPTER"})," into our service and use it to localize our commands and messages:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { Injectable, Inject, OnModuleInit } from '@nestjs/common';\nimport { DefaultLocalizationAdapter, localizationMapByKey, LOCALIZATION_ADAPTER } from '@globalart/nestcord';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService implements OnModuleInit {\n public constructor(\n @Inject(LOCALIZATION_ADAPTER)\n private readonly localizationAdapter: DefaultLocalizationAdapter\n ) {\n }\n\n @SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: localizationMapByKey('commands.ping.name'),\n descriptionLocalizations: localizationMapByKey('commands.ping.name')\n })\n public ping(@Context() [interaction]: SlashCommandContext) {\n const message = this.localizationAdapter.getTranslation(\n 'commands.ping.description',\n interaction.locale\n );\n return interaction.reply(message);\n }\n}\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Or you can use ",(0,t.jsx)(n.code,{children:"@CurrentTranslate"})," decorator to get the current translation from context:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { Injectable, Inject, OnModuleInit } from '@nestjs/common';\nimport { DefaultLocalizationAdapter, CurrentTranslate, localizationMapByKey, TranslationFn } from '@globalart/nestcord/localization';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService implements OnModuleInit {\n @SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: localizationMapByKey('commands.ping.name'),\n descriptionLocalizations: localizationMapByKey('commands.ping.name')\n })\n public ping(\n @Context() [interaction]: SlashCommandContext,\n @CurrentTranslate() t: TranslationFn\n ) {\n const message = t('commands.ping.description');\n return interaction.reply(message);\n }\n}\n"})}),"\n",(0,t.jsx)(n.admonition,{type:"info",children:(0,t.jsxs)(n.p,{children:["Function ",(0,t.jsx)(n.code,{children:"localizationMapByKey"})," are used to localize the command name and description. You pass the translation key or localization map as\nan argument to the function."]})}),"\n",(0,t.jsx)(n.h4,{id:"setting-up-localized-commands",children:"Setting up localized commands"}),"\n",(0,t.jsx)(n.p,{children:"You can set what locales the command will be localized"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"@SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: localizationMapByKey('commands.ping.name', ['en', 'ru']),\n descriptionLocalizations: localizationMapByKey('commands.ping.name', ['en', 'ru'])\n})\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Or just pass a localization object with the location id and translation key to the ",(0,t.jsx)(n.code,{children:"nameLocalization"})," and ",(0,t.jsx)(n.code,{children:"descriptionLocalizations"}),"\nproperties"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"@SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: {\n en: 'command.ping.name',\n ru: 'command.ping.name'\n },\n descriptionLocalizations: {\n en: 'command.ping.description',\n ru: 'command.ping.description'\n }\n})\n"})}),"\n",(0,t.jsx)(n.p,{children:"Congratulations! You have successfully created your first localized command with NestCord!"})]})}function p(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},5710:(e,n,o)=>{o.d(n,{R:()=>s,x:()=>l});var t=o(758);const a={},i=t.createContext(a);function s(e){const n=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),t.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/d347213b.c4a52c6e.js b/assets/js/d347213b.c4a52c6e.js deleted file mode 100644 index 1643936..0000000 --- a/assets/js/d347213b.c4a52c6e.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[467],{792:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>r,contentTitle:()=>s,default:()=>p,frontMatter:()=>i,metadata:()=>l,toc:()=>c});var t=o(6070),a=o(5710);const i={id:"localization",title:"Localization",sidebar_position:2},s=void 0,l={id:"recipes/localization",title:"Localization",description:"Is a lightweight localization module for NestCord. It allows you to easily localize your bot's",source:"@site/content/recipes/localization.md",sourceDirName:"recipes",slug:"/recipes/localization",permalink:"/nestcord/recipes/localization",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/recipes/localization.md",tags:[],version:"current",sidebarPosition:2,frontMatter:{id:"localization",title:"Localization",sidebar_position:2},sidebar:"docsSidebar",previous:{title:"Pagination",permalink:"/nestcord/recipes/pagination"},next:{title:"Stat Reporter",permalink:"/nestcord/recipes/stat-reporter"}},r={},c=[{value:"Usage",id:"usage",level:2},{value:"Adapters",id:"adapters",level:2},{value:"Custom Adapters",id:"custom-adapters",level:4},{value:"Resolvers",id:"resolvers",level:2},{value:"Custom Resolvers",id:"custom-resolvers",level:4},{value:"Localization",id:"localization",level:2},{value:"Setting up localized commands",id:"setting-up-localized-commands",level:4}];function d(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",h4:"h4",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,a.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(n.p,{children:["Is a lightweight localization module for ",(0,t.jsx)(n.a,{href:"https://nestcord.globalart.dev/",children:"NestCord"}),". It allows you to easily localize your bot's\ncommands and messages. The module provides a simple API for managing locales and translations, as well as a powerful localization adapter\nsystem."]}),"\n",(0,t.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,t.jsxs)(n.p,{children:["Once the installation process is complete, we can import the ",(0,t.jsx)(n.code,{children:"NestCordLocalizationModule"})," with your ",(0,t.jsx)(n.code,{children:"NestCordModule"})," into the root ",(0,t.jsx)(n.code,{children:"AppModule"}),":"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { NestCordLocalizationModule, DefaultLocalizationAdapter, UserResolver } from '@globalart/nestcord';\nimport { AppService } from './app.service';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: process.env.DISCORD_TOKEN,\n intents: [\n IntentsBitField.Flags.Guilds,\n IntentsBitField.Flags.DirectMessages,\n IntentsBitField.Flags.GuildMembers,\n IntentsBitField.Flags.GuildMessages,\n IntentsBitField.Flags.MessageContent\n ],\n prefix: '!',\n development: [process.env.DISCORD_TEST_GUILD]\n }),\n NestCordLocalizationModule.forRoot({\n resolvers: UserResolver,\n // Also you can provide class for support injection by @Inject\n adapter: new DefaultLocalizationAdapter({\n fallbackLocale: 'en-US',\n locales: {\n 'en-US': {\n 'commands.ping.name': 'ping',\n 'commands.ping.description': 'Pong!'\n },\n ru: {\n 'commands.ping.name': '\u043f\u0438\u043d\u0433',\n 'commands.ping.description': '\u041f\u043e\u043d\u0433!'\n }\n }\n })\n })\n ],\n providers: [AppService]\n})\nexport class AppModule {\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"adapters",children:"Adapters"}),"\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"DefaultLocalizationAdapter"})," is a simple adapter that allows you to provide a map of locales and translations."]}),"\n",(0,t.jsxs)(n.p,{children:["Also you can use the ",(0,t.jsx)(n.code,{children:"NestedLocalizationAdapter"})," that allows you to organize translation keys into objects"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { NestCordLocalizationModule, NestedLocalizationAdapter, UserResolver } from '@globalart/nestcord/localization';\n\nNestCordLocalizationModule.forRoot({\n resolvers: UserResolver,\n adapter: new NestedLocalizationAdapter({\n fallbackLocale: 'en-US',\n locales: {\n 'en-US': {\n 'commands': {\n 'ping': {\n 'name': 'ping',\n 'description': 'Pong!'\n }\n }\n },\n ru: {\n 'commands': {\n 'ping': {\n 'name': '\u043f\u0438\u043d\u0433',\n 'description': '\u041f\u043e\u043d\u0433!'\n }\n }\n }\n }\n })\n})\n\n"})}),"\n",(0,t.jsx)(n.admonition,{type:"info",children:(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.code,{children:"DefaultLocalizationAdapter"})," and ",(0,t.jsx)(n.code,{children:"NestedLocalizationAdapter"})," can translate your localization strings and placeholders (e.g ",(0,t.jsx)(n.code,{children:"{{username}}"}),")"]})}),"\n",(0,t.jsx)(n.h4,{id:"custom-adapters",children:"Custom Adapters"}),"\n",(0,t.jsxs)(n.p,{children:["Also, you can create your own localization adapter. Just implement the ",(0,t.jsx)(n.code,{children:"BaseLocalizationAdapter"})," interface:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { BaseLocalizationAdapter } from '@globalart/nestcord/localization';\n\ninterface CustomLocalizationOptions {\n fallbackLocale: string;\n locales: Record>;\n}\n\nexport class CustomLocalizationAdapter extends BaseLocalizationAdapter {\n public getTranslation(key: string, locale: string, ...args: any[]): string {\n return `${key} by ${locale}`;\n }\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"resolvers",children:"Resolvers"}),"\n",(0,t.jsxs)(n.p,{children:["Resolvers are used to get the locale for translation. By default, NestCord provides two resolvers: ",(0,t.jsx)(n.code,{children:"UserResolver"})," and ",(0,t.jsx)(n.code,{children:"GuildResolver"}),"."]}),"\n",(0,t.jsxs)(n.table,{children:[(0,t.jsx)(n.thead,{children:(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.th,{children:"Resolver"}),(0,t.jsx)(n.th,{children:"Description"})]})}),(0,t.jsxs)(n.tbody,{children:[(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:"UserResolver"}),(0,t.jsxs)(n.td,{children:["Gets the locale from the user's locale property (",(0,t.jsx)(n.code,{children:"interaction.locale"}),")"]})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:"GuildResolver"}),(0,t.jsxs)(n.td,{children:["Gets the locale from the guild's locale property (",(0,t.jsx)(n.code,{children:"interaction.guildLocale"}),")"]})]})]})]}),"\n",(0,t.jsx)(n.h4,{id:"custom-resolvers",children:"Custom Resolvers"}),"\n",(0,t.jsxs)(n.p,{children:["Also, you can create your own Resolver. Just implement the ",(0,t.jsx)(n.code,{children:"LocaleResolver"})," interface:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { CommandContext, LocaleResolver } from '@globalart/nestcord';\nimport { ExecutionContext, Injectable } from '@nestjs/common';\nimport { NestCordExecutionContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class GuildResolver implements LocaleResolver {\n resolve(context: ExecutionContext): string | string[] | undefined {\n const nestcordContext = NestCordExecutionContext.create(context);\n const [interaction] = nestcordContext.getContext();\n\n return interaction.guildLocale;\n }\n}\n"})}),"\n",(0,t.jsx)(n.h2,{id:"localization",children:"Localization"}),"\n",(0,t.jsxs)(n.p,{children:["We can inject the ",(0,t.jsx)(n.code,{children:"LOCALIZATION_ADAPTER"})," into our service and use it to localize our commands and messages:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { Injectable, Inject, OnModuleInit } from '@nestjs/common';\nimport { DefaultLocalizationAdapter, localizationMapByKey, LOCALIZATION_ADAPTER } from '@globalart/nestcord';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService implements OnModuleInit {\n public constructor(\n @Inject(LOCALIZATION_ADAPTER)\n private readonly localizationAdapter: DefaultLocalizationAdapter\n ) {\n }\n\n @SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: localizationMapByKey('commands.ping.name'),\n descriptionLocalizations: localizationMapByKey('commands.ping.name')\n })\n public ping(@Context() [interaction]: SlashCommandContext) {\n const message = this.localizationAdapter.getTranslation(\n 'commands.ping.description',\n interaction.locale\n );\n return interaction.reply(message);\n }\n}\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Or you can use ",(0,t.jsx)(n.code,{children:"@CurrentTranslate"})," decorator to get the current translation from context:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"import { Injectable, Inject, OnModuleInit } from '@nestjs/common';\nimport { DefaultLocalizationAdapter, CurrentTranslate, localizationMapByKey, TranslationFn } from '@globalart/nestcord/localization';\nimport { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppService implements OnModuleInit {\n @SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: localizationMapByKey('commands.ping.name'),\n descriptionLocalizations: localizationMapByKey('commands.ping.name')\n })\n public ping(\n @Context() [interaction]: SlashCommandContext,\n @CurrentTranslate() t: TranslationFn\n ) {\n const message = t('commands.ping.description');\n return interaction.reply(message);\n }\n}\n"})}),"\n",(0,t.jsx)(n.admonition,{type:"info",children:(0,t.jsxs)(n.p,{children:["Function ",(0,t.jsx)(n.code,{children:"localizationMapByKey"})," are used to localize the command name and description. You pass the translation key or localization map as\nan argument to the function."]})}),"\n",(0,t.jsx)(n.h4,{id:"setting-up-localized-commands",children:"Setting up localized commands"}),"\n",(0,t.jsx)(n.p,{children:"You can set what locales the command will be localized"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"@SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: localizationMapByKey('commands.ping.name', ['en', 'ru']),\n descriptionLocalizations: localizationMapByKey('commands.ping.name', ['en', 'ru'])\n})\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Or just pass a localization object with the location id and translation key to the ",(0,t.jsx)(n.code,{children:"nameLocalization"})," and ",(0,t.jsx)(n.code,{children:"descriptionLocalizations"}),"\nproperties"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-typescript",children:"@SlashCommand({\n name: 'ping',\n description: 'Pong!',\n nameLocalizations: {\n en: 'command.ping.name',\n ru: 'command.ping.name'\n },\n descriptionLocalizations: {\n en: 'command.ping.description',\n ru: 'command.ping.description'\n }\n})\n"})}),"\n",(0,t.jsx)(n.p,{children:"Congratulations! You have successfully created your first localized command with NestCord!"})]})}function p(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(d,{...e})}):d(e)}},5710:(e,n,o)=>{o.d(n,{R:()=>s,x:()=>l});var t=o(758);const a={},i=t.createContext(a);function s(e){const n=t.useContext(i);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:s(e.components),t.createElement(i.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e7393073.38ec6faf.js b/assets/js/e7393073.38ec6faf.js deleted file mode 100644 index 0cec7ab..0000000 --- a/assets/js/e7393073.38ec6faf.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[140],{6845:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>r,default:()=>p,frontMatter:()=>s,metadata:()=>i,toc:()=>c});var o=n(6070),a=n(5710);const s={id:"modals",title:"Modals",sidebar_position:4},r=void 0,i={id:"interactions/modals",title:"Modals",description:"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We'll cover how to create, show, and receive modal forms using nestcord",source:"@site/content/interactions/modals.md",sourceDirName:"interactions",slug:"/interactions/modals",permalink:"/nestcord/interactions/modals",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/modals.md",tags:[],version:"current",sidebarPosition:4,frontMatter:{id:"modals",title:"Modals",sidebar_position:4},sidebar:"docsSidebar",previous:{title:"Message Components",permalink:"/nestcord/interactions/message-components"},next:{title:"Text Commands",permalink:"/nestcord/text-commands"}},l={},c=[{value:"Dynamic Modal",id:"dynamic-modal",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We'll cover how to create, show, and receive modal forms using nestcord"}),"\n",(0,o.jsx)("img",{src:"/img/content/modal.png",alt:"Modal",width:"500"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="app.modals.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, Modal, ModalContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppModals {\n @Modal('pizza')\n public onModal(@Ctx() [interaction]: ModalContext) {\n return interaction.reply({\n content: `Your fav pizza : ${interaction.fields.getTextInputValue('pizza')}`\n });\n }\n}\n"})}),"\n",(0,o.jsx)(t.h3,{id:"dynamic-modal",children:"Dynamic Modal"}),"\n",(0,o.jsxs)(t.p,{children:["You can create modals with dynamic ",(0,o.jsx)(t.code,{children:"id"})," field. This is useful for passing metadata to modals."]}),"\n",(0,o.jsxs)(t.p,{children:["Dynamic modals uses ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/path-to-regexp",children:"path-to-regexp"})," format to perform regexp matching. Turn a path string such as ",(0,o.jsx)(t.code,{children:"user/:name"})," into a regular expression."]}),"\n",(0,o.jsx)(t.p,{children:"To create a Dynamic modal"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",children:"new ModalBuilder()\n .setTitle('What your fav pizza?')\n .setCustomId('pizza/12345')\n .setComponents([\n new ActionRowBuilder().addComponents([\n new TextInputBuilder()\n .setCustomId('pizza')\n .setLabel('???')\n .setStyle(TextInputStyle.Paragraph)\n ])\n ])\n"})}),"\n",(0,o.jsx)(t.p,{children:"To receive a Dynamic modal"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="app.modals.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, Modal, ModalContext,ModalParam } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppModals {\n @Modal('pizza/:value')\n public onModal(@Ctx() [interaction]: ModalContext, @ModalParam('value') value: string) {\n return interaction.reply({\n content: `Your fav pizza ${value} : ${interaction.fields.getTextInputValue('pizza')}`\n });\n }\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>i});var o=n(758);const a={},s=o.createContext(a);function r(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/e7393073.9b602c33.js b/assets/js/e7393073.9b602c33.js new file mode 100644 index 0000000..5fea24d --- /dev/null +++ b/assets/js/e7393073.9b602c33.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[140],{6845:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>l,contentTitle:()=>r,default:()=>p,frontMatter:()=>s,metadata:()=>i,toc:()=>c});var o=n(6070),a=n(5710);const s={id:"modals",title:"Modals",sidebar_position:4},r=void 0,i={id:"interactions/modals",title:"Modals",description:"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We'll cover how to create, show, and receive modal forms using nestcord",source:"@site/content/interactions/modals.md",sourceDirName:"interactions",slug:"/interactions/modals",permalink:"/interactions/modals",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/interactions/modals.md",tags:[],version:"current",sidebarPosition:4,frontMatter:{id:"modals",title:"Modals",sidebar_position:4},sidebar:"docsSidebar",previous:{title:"Message Components",permalink:"/interactions/message-components"},next:{title:"Text Commands",permalink:"/text-commands"}},l={},c=[{value:"Dynamic Modal",id:"dynamic-modal",level:3}];function d(e){const t={a:"a",code:"code",h3:"h3",p:"p",pre:"pre",...(0,a.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.p,{children:"With modals you can create pop-up forms that allow users to provide you with formatted inputs through submissions. We'll cover how to create, show, and receive modal forms using nestcord"}),"\n",(0,o.jsx)("img",{src:"/img/content/modal.png",alt:"Modal",width:"500"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="app.modals.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, Modal, ModalContext } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppModals {\n @Modal('pizza')\n public onModal(@Ctx() [interaction]: ModalContext) {\n return interaction.reply({\n content: `Your fav pizza : ${interaction.fields.getTextInputValue('pizza')}`\n });\n }\n}\n"})}),"\n",(0,o.jsx)(t.h3,{id:"dynamic-modal",children:"Dynamic Modal"}),"\n",(0,o.jsxs)(t.p,{children:["You can create modals with dynamic ",(0,o.jsx)(t.code,{children:"id"})," field. This is useful for passing metadata to modals."]}),"\n",(0,o.jsxs)(t.p,{children:["Dynamic modals uses ",(0,o.jsx)(t.a,{href:"https://www.npmjs.com/package/path-to-regexp",children:"path-to-regexp"})," format to perform regexp matching. Turn a path string such as ",(0,o.jsx)(t.code,{children:"user/:name"})," into a regular expression."]}),"\n",(0,o.jsx)(t.p,{children:"To create a Dynamic modal"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",children:"new ModalBuilder()\n .setTitle('What your fav pizza?')\n .setCustomId('pizza/12345')\n .setComponents([\n new ActionRowBuilder().addComponents([\n new TextInputBuilder()\n .setCustomId('pizza')\n .setLabel('???')\n .setStyle(TextInputStyle.Paragraph)\n ])\n ])\n"})}),"\n",(0,o.jsx)(t.p,{children:"To receive a Dynamic modal"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-typescript",metastring:'title="app.modals.ts"',children:"import { Injectable } from '@nestjs/common';\nimport { Context, Modal, ModalContext,ModalParam } from '@globalart/nestcord';\n\n@Injectable()\nexport class AppModals {\n @Modal('pizza/:value')\n public onModal(@Ctx() [interaction]: ModalContext, @ModalParam('value') value: string) {\n return interaction.reply({\n content: `Your fav pizza ${value} : ${interaction.fields.getTextInputValue('pizza')}`\n });\n }\n}\n"})})]})}function p(e={}){const{wrapper:t}={...(0,a.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(d,{...e})}):d(e)}},5710:(e,t,n)=>{n.d(t,{R:()=>r,x:()=>i});var o=n(758);const a={},s=o.createContext(a);function r(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:r(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ec3f407b.3d78b163.js b/assets/js/ec3f407b.3d78b163.js new file mode 100644 index 0000000..42b0a7d --- /dev/null +++ b/assets/js/ec3f407b.3d78b163.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[931],{9451:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>u});var r=n(6070),s=n(5710),o=n(8060),a=n(7113);const l={id:"intro",slug:"/",title:"Introduction",description:"A module for creating Discord bots using NestJS, based on Discord.js.",sidebar_position:1},i=void 0,c={id:"intro",title:"Introduction",description:"A module for creating Discord bots using NestJS, based on Discord.js.",source:"@site/content/intro.md",sourceDirName:".",slug:"/",permalink:"/",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/intro.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"intro",slug:"/",title:"Introduction",description:"A module for creating Discord bots using NestJS, based on Discord.js.",sidebar_position:1},sidebar:"docsSidebar",next:{title:"Getting Started",permalink:"/start"}},d={},u=[{value:"About",id:"about",level:2},{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{align:"center",children:[(0,r.jsx)("h1",{children:(0,r.jsx)("a",{href:"#",children:(0,r.jsx)("img",{src:"https://nestcord.globalart.dev/img/logo.png",alt:"NestCord Logo"})})}),(0,r.jsxs)(t.p,{children:["\ud83e\udd16 A module for creating ",(0,r.jsxs)("b",{children:[(0,r.jsx)("a",{href:"https://discord.com/",children:"Discord"})," bots"]})," using ",(0,r.jsx)("a",{href:"https://nestjs.com",children:"NestJS"}),", based on ",(0,r.jsx)("a",{href:"https://discord.js.org/",children:"Discord.js"})]}),(0,r.jsx)("br",{}),(0,r.jsx)("br",{}),(0,r.jsxs)(t.p,{children:[(0,r.jsx)("a",{href:"https://nestcord.globalart.dev",children:"Documentation \u2728"})," \u2003 ",(0,r.jsx)("a",{href:"https://github.com/GlobalArtInc/nestcord",children:"Source code \ud83e\udea1"})," \u2003 ",(0,r.jsx)("a",{href:"https://github.com/GlobalArtInc/nestcord/tree/master/examples",children:"Examples \ud83d\udee0\ufe0f"})," \u2003 ",(0,r.jsx)("a",{href:"https://discord.gg/BBFhU8g",children:"Community \ud83d\udcac"})]})]}),"\n",(0,r.jsx)("br",{}),"\n",(0,r.jsxs)("p",{align:"center",children:[(0,r.jsx)("a",{href:"https://img.shields.io/npm/v/@globalart/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/npm/v/@globalart/nestcord",alt:"NPM Version"})}),(0,r.jsx)("a",{href:"https://img.shields.io/npm/l/@globalart/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/npm/l/@globalart/nestcord",alt:"NPM License"})}),(0,r.jsx)("a",{href:"https://img.shields.io/npm/dm/@globalart/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/npm/dm/@globalart/nestcord",alt:"NPM Downloads"})}),(0,r.jsx)("a",{href:"https://img.shields.io/github/last-commit/@GlobalArtInc/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/github/last-commit/GlobalArtInc/nestcord",alt:"Last commit"})})]}),"\n",(0,r.jsx)(t.h2,{id:"about",children:"About"}),"\n",(0,r.jsxs)(t.p,{children:["This package uses the best of the NodeJS world under the hood. ",(0,r.jsx)(t.a,{href:"https://github.com/discordjs/discord.js",children:"Discord.js"})," is the most powerful\nlibrary for creating bots and ",(0,r.jsx)(t.a,{href:"https://github.com/nestjs",children:"Nest.js"})," is a progressive framework for creating well-architectured applications.\nThis module provides fast and easy way for creating Discord bots and deep integration with your NestJS application."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Features"})}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:"Simple. Flexible. Easy to use."}),"\n",(0,r.jsx)(t.li,{children:"Ability to create custom decorators."}),"\n",(0,r.jsx)(t.li,{children:"Interact with Discord (Slash Commands, Context Menus, Message Components, Listeners)."}),"\n",(0,r.jsx)(t.li,{children:"Full support of NestJS guards, interceptors, filters and pipes!"}),"\n"]}),"\n",(0,r.jsxs)(t.p,{children:["For questions and support please use\nthe ",(0,r.jsx)(t.a,{href:"https://github.com/GlobalArtInc/nestcord/issues/new?assignees=&labels=question&template=question.yml",children:"Issues"}),"."]}),"\n",(0,r.jsx)(t.h2,{id:"installation",children:"Installation"}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Node.js 16.6.0 or newer is required."})}),"\n",(0,r.jsxs)(o.A,{groupId:"npm2yarn",children:[(0,r.jsx)(a.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ npm install @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ yarn add @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ pnpm add @globalart/nestcord discord.js\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsxs)(t.p,{children:["Once the installation process is complete, we can import the ",(0,r.jsx)(t.code,{children:"NestCordModule"})," into the root ",(0,r.jsx)(t.code,{children:"AppModule"}),":"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\nimport { AppUpdate } from './app.update';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: 'DISCORD_BOT_TOKEN',\n intents: [IntentsBitField.Flags.Guilds]\n })\n ],\n providers: [AppUpdate]\n})\nexport class AppModule {}\n"})}),"\n",(0,r.jsxs)(t.p,{children:["Then create ",(0,r.jsx)(t.code,{children:"app.update.ts"})," file and add ",(0,r.jsx)(t.code,{children:"On"}),"/",(0,r.jsx)(t.code,{children:"Once"})," decorators for handling Discord API events:"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.update.ts"',children:"import { Injectable, Logger } from '@nestjs/common';\nimport { Context, On, Once, ContextOf } from '@globalart/nestcord';\nimport { Client } from 'discord.js';\n\n@Injectable()\nexport class AppUpdate {\n private readonly logger = new Logger(AppUpdate.name);\n\n public constructor(private readonly client: Client) {}\n\n @Once('ready')\n public onReady(@Context() [client]: ContextOf<'ready'>) {\n this.logger.log(`Bot logged in as ${client.user.username}`);\n }\n\n @On('warn')\n public onWarn(@Context() [message]: ContextOf<'warn'>) {\n this.logger.warn(message);\n }\n}\n"})}),"\n",(0,r.jsxs)(t.p,{children:["Whenever you need to handle any event data, use the ",(0,r.jsx)(t.code,{children:"Context"})," decorator."]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7113:(e,t,n)=>{n.d(t,{A:()=>a});n(758);var r=n(3526);const s={tabItem:"tabItem_A6Wz"};var o=n(6070);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,a),hidden:n,children:t})}},8060:(e,t,n)=>{n.d(t,{A:()=>w});var r=n(758),s=n(3526),o=n(5394),a=n(5557),l=n(8063),i=n(5799),c=n(1836),d=n(8552);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,c.X)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const s=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i.aZ)(o),(0,r.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(s.location.search);t.set(o,e),s.replace({...s.location,search:t.toString()})}),[o,s])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,o=h(e),[a,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[c,u]=m({queryString:n,groupId:s}),[g,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,o]=(0,d.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:s}),f=(()=>{const e=c??g;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,o]),tabValues:o}}var b=n(2253);const f={tabList:"tabList_UwLV",tabItem:"tabItem_Clxf"};var x=n(6070);function j(e){let{className:t,block:n,selectedValue:r,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),d=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==r&&(c(t),a(s))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:u,onClick:d,...o,className:(0,s.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,x.jsxs)("div",{className:(0,s.A)("tabs-container",f.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,b.A)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(t))}},5710:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>l});var r=n(758);const s={},o=r.createContext(s);function a(e){const t=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/ec3f407b.87d9c978.js b/assets/js/ec3f407b.87d9c978.js deleted file mode 100644 index b976867..0000000 --- a/assets/js/ec3f407b.87d9c978.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[931],{9451:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>u});var r=n(6070),s=n(5710),o=n(8060),a=n(7113);const l={id:"intro",slug:"/",title:"Introduction",description:"A module for creating Discord bots using NestJS, based on Discord.js.",sidebar_position:1},i=void 0,c={id:"intro",title:"Introduction",description:"A module for creating Discord bots using NestJS, based on Discord.js.",source:"@site/content/intro.md",sourceDirName:".",slug:"/",permalink:"/nestcord/",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/intro.md",tags:[],version:"current",sidebarPosition:1,frontMatter:{id:"intro",slug:"/",title:"Introduction",description:"A module for creating Discord bots using NestJS, based on Discord.js.",sidebar_position:1},sidebar:"docsSidebar",next:{title:"Getting Started",permalink:"/nestcord/start"}},d={},u=[{value:"About",id:"about",level:2},{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2}];function h(e){const t={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{align:"center",children:[(0,r.jsx)("h1",{children:(0,r.jsx)("a",{href:"#",children:(0,r.jsx)("img",{src:"https://nestcord.globalart.dev/img/logo.png",alt:"NestCord Logo"})})}),(0,r.jsxs)(t.p,{children:["\ud83e\udd16 A module for creating ",(0,r.jsxs)("b",{children:[(0,r.jsx)("a",{href:"https://discord.com/",children:"Discord"})," bots"]})," using ",(0,r.jsx)("a",{href:"https://nestjs.com",children:"NestJS"}),", based on ",(0,r.jsx)("a",{href:"https://discord.js.org/",children:"Discord.js"})]}),(0,r.jsx)("br",{}),(0,r.jsx)("br",{}),(0,r.jsxs)(t.p,{children:[(0,r.jsx)("a",{href:"https://nestcord.globalart.dev",children:"Documentation \u2728"})," \u2003 ",(0,r.jsx)("a",{href:"https://github.com/GlobalArtInc/nestcord",children:"Source code \ud83e\udea1"})," \u2003 ",(0,r.jsx)("a",{href:"https://github.com/GlobalArtInc/nestcord/tree/master/examples",children:"Examples \ud83d\udee0\ufe0f"})," \u2003 ",(0,r.jsx)("a",{href:"https://discord.gg/BBFhU8g",children:"Community \ud83d\udcac"})]})]}),"\n",(0,r.jsx)("br",{}),"\n",(0,r.jsxs)("p",{align:"center",children:[(0,r.jsx)("a",{href:"https://img.shields.io/npm/v/@globalart/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/npm/v/@globalart/nestcord",alt:"NPM Version"})}),(0,r.jsx)("a",{href:"https://img.shields.io/npm/l/@globalart/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/npm/l/@globalart/nestcord",alt:"NPM License"})}),(0,r.jsx)("a",{href:"https://img.shields.io/npm/dm/@globalart/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/npm/dm/@globalart/nestcord",alt:"NPM Downloads"})}),(0,r.jsx)("a",{href:"https://img.shields.io/github/last-commit/@GlobalArtInc/nestcord",children:(0,r.jsx)("img",{src:"https://img.shields.io/github/last-commit/GlobalArtInc/nestcord",alt:"Last commit"})})]}),"\n",(0,r.jsx)(t.h2,{id:"about",children:"About"}),"\n",(0,r.jsxs)(t.p,{children:["This package uses the best of the NodeJS world under the hood. ",(0,r.jsx)(t.a,{href:"https://github.com/discordjs/discord.js",children:"Discord.js"})," is the most powerful\nlibrary for creating bots and ",(0,r.jsx)(t.a,{href:"https://github.com/nestjs",children:"Nest.js"})," is a progressive framework for creating well-architectured applications.\nThis module provides fast and easy way for creating Discord bots and deep integration with your NestJS application."]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Features"})}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsx)(t.li,{children:"Simple. Flexible. Easy to use."}),"\n",(0,r.jsx)(t.li,{children:"Ability to create custom decorators."}),"\n",(0,r.jsx)(t.li,{children:"Interact with Discord (Slash Commands, Context Menus, Message Components, Listeners)."}),"\n",(0,r.jsx)(t.li,{children:"Full support of NestJS guards, interceptors, filters and pipes!"}),"\n"]}),"\n",(0,r.jsxs)(t.p,{children:["For questions and support please use\nthe ",(0,r.jsx)(t.a,{href:"https://github.com/GlobalArtInc/nestcord/issues/new?assignees=&labels=question&template=question.yml",children:"Issues"}),"."]}),"\n",(0,r.jsx)(t.h2,{id:"installation",children:"Installation"}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Node.js 16.6.0 or newer is required."})}),"\n",(0,r.jsxs)(o.A,{groupId:"npm2yarn",children:[(0,r.jsx)(a.A,{value:"npm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ npm install @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ yarn add @globalart/nestcord discord.js\n"})})}),(0,r.jsx)(a.A,{value:"pnpm",label:"pnpm",children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-bash",children:"$ pnpm add @globalart/nestcord discord.js\n"})})})]}),"\n",(0,r.jsx)(t.h2,{id:"usage",children:"Usage"}),"\n",(0,r.jsxs)(t.p,{children:["Once the installation process is complete, we can import the ",(0,r.jsx)(t.code,{children:"NestCordModule"})," into the root ",(0,r.jsx)(t.code,{children:"AppModule"}),":"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.module.ts"',children:"import { NestCordModule } from '@globalart/nestcord';\nimport { Module } from '@nestjs/common';\nimport { IntentsBitField } from 'discord.js';\nimport { AppUpdate } from './app.update';\n\n@Module({\n imports: [\n NestCordModule.forRoot({\n token: 'DISCORD_BOT_TOKEN',\n intents: [IntentsBitField.Flags.Guilds]\n })\n ],\n providers: [AppUpdate]\n})\nexport class AppModule {}\n"})}),"\n",(0,r.jsxs)(t.p,{children:["Then create ",(0,r.jsx)(t.code,{children:"app.update.ts"})," file and add ",(0,r.jsx)(t.code,{children:"On"}),"/",(0,r.jsx)(t.code,{children:"Once"})," decorators for handling Discord API events:"]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",metastring:'title="src/app.update.ts"',children:"import { Injectable, Logger } from '@nestjs/common';\nimport { Context, On, Once, ContextOf } from '@globalart/nestcord';\nimport { Client } from 'discord.js';\n\n@Injectable()\nexport class AppUpdate {\n private readonly logger = new Logger(AppUpdate.name);\n\n public constructor(private readonly client: Client) {}\n\n @Once('ready')\n public onReady(@Context() [client]: ContextOf<'ready'>) {\n this.logger.log(`Bot logged in as ${client.user.username}`);\n }\n\n @On('warn')\n public onWarn(@Context() [message]: ContextOf<'warn'>) {\n this.logger.warn(message);\n }\n}\n"})}),"\n",(0,r.jsxs)(t.p,{children:["Whenever you need to handle any event data, use the ",(0,r.jsx)(t.code,{children:"Context"})," decorator."]})]})}function p(e={}){const{wrapper:t}={...(0,s.R)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},7113:(e,t,n)=>{n.d(t,{A:()=>a});n(758);var r=n(3526);const s={tabItem:"tabItem_A6Wz"};var o=n(6070);function a(e){let{children:t,hidden:n,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.A)(s.tabItem,a),hidden:n,children:t})}},8060:(e,t,n)=>{n.d(t,{A:()=>w});var r=n(758),s=n(3526),o=n(5394),a=n(5557),l=n(8063),i=n(5799),c=n(1836),d=n(8552);function u(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return u(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,c.X)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const s=(0,a.W6)(),o=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i.aZ)(o),(0,r.useCallback)((e=>{if(!o)return;const t=new URLSearchParams(s.location.search);t.set(o,e),s.replace({...s.location,search:t.toString()})}),[o,s])]}function g(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,o=h(e),[a,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:o}))),[c,u]=m({queryString:n,groupId:s}),[g,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,o]=(0,d.Dv)(n);return[s,(0,r.useCallback)((e=>{n&&o.set(e)}),[n,o])]}({groupId:s}),f=(()=>{const e=c??g;return p({value:e,tabValues:o})?e:null})();(0,l.A)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);i(e),u(e),b(e)}),[u,b,o]),tabValues:o}}var b=n(2253);const f={tabList:"tabList_UwLV",tabItem:"tabItem_Clxf"};var x=n(6070);function j(e){let{className:t,block:n,selectedValue:r,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.a_)(),d=e=>{const t=e.currentTarget,n=i.indexOf(t),s=l[n].value;s!==r&&(c(t),a(s))},u=e=>{let t=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.A)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:o}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:u,onClick:d,...o,className:(0,s.A)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function v(e){let{lazy:t,children:n,selectedValue:s}=e;const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:o.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function y(e){const t=g(e);return(0,x.jsxs)("div",{className:(0,s.A)("tabs-container",f.tabList),children:[(0,x.jsx)(j,{...t,...e}),(0,x.jsx)(v,{...t,...e})]})}function w(e){const t=(0,b.A)();return(0,x.jsx)(y,{...e,children:u(e.children)},String(t))}},5710:(e,t,n)=>{n.d(t,{R:()=>a,x:()=>l});var r=n(758);const s={},o=r.createContext(s);function a(e){const t=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),r.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/f217256c.6c845206.js b/assets/js/f217256c.6c845206.js deleted file mode 100644 index c7f8ffb..0000000 --- a/assets/js/f217256c.6c845206.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[497],{6813:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>r,default:()=>a,frontMatter:()=>s,metadata:()=>c,toc:()=>l});var o=t(6070),i=t(5710);const s={id:"commit-convention",title:"Commit convention",sidebar_position:3},r=void 0,c={id:"contributing/commit-convention",title:"Commit convention",description:"Git Commit Message Convention",source:"@site/content/contributing/commit-convention.md",sourceDirName:"contributing",slug:"/contributing/commit-convention",permalink:"/nestcord/contributing/commit-convention",draft:!1,unlisted:!1,editUrl:"https://github.com/GlobalArtInc/nestcord/tree/master/docs/content/contributing/commit-convention.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{id:"commit-convention",title:"Commit convention",sidebar_position:3},sidebar:"docsSidebar",previous:{title:"Code of Conduct",permalink:"/nestcord/contributing/code-of-conduct"},next:{title:"Funding",permalink:"/nestcord/contributing/funding"}},d={},l=[{value:"Git Commit Message Convention",id:"git-commit-message-convention",level:2},{value:"TL;DR:",id:"tldr",level:4},{value:"Full Message Format",id:"full-message-format",level:3},{value:"Revert",id:"revert",level:3},{value:"Type",id:"type",level:3},{value:"Scope",id:"scope",level:3},{value:"Subject",id:"subject",level:3},{value:"Body",id:"body",level:3},{value:"Footer",id:"footer",level:3}];function h(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,i.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.h2,{id:"git-commit-message-convention",children:"Git Commit Message Convention"}),"\n",(0,o.jsx)(n.admonition,{type:"info",children:(0,o.jsxs)(n.p,{children:["This is adapted from ",(0,o.jsx)(n.a,{href:"https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular",children:"Angular's commit convention"}),"."]})}),"\n",(0,o.jsx)(n.h4,{id:"tldr",children:"TL;DR:"}),"\n",(0,o.jsx)(n.p,{children:"Commit titles must match the following regex:"}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{className:"language-js",children:"/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip)(\\(.+\\))?: .{1,72}/;\n"})}),"\n",(0,o.jsx)(n.h3,{id:"full-message-format",children:"Full Message Format"}),"\n",(0,o.jsxs)(n.p,{children:["A commit message consists of a ",(0,o.jsx)(n.strong,{children:"header"}),", ",(0,o.jsx)(n.strong,{children:"body"})," and ",(0,o.jsx)(n.strong,{children:"footer"}),". The header has a ",(0,o.jsx)(n.strong,{children:"type"}),", ",(0,o.jsx)(n.strong,{children:"scope"})," and ",(0,o.jsx)(n.strong,{children:"subject"}),":"]}),"\n",(0,o.jsx)(n.pre,{children:(0,o.jsx)(n.code,{children:"(): \n\n\n\n