Compare commits

...

2 Commits

Author SHA1 Message Date
109636586a 2025-03-28 13:44:58 +00:00
8d0c8ce6b5 2025-03-28 13:39:04 +00:00
15 changed files with 985 additions and 4 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

147
README.md
View File

@ -1,6 +1,145 @@
## Discord # Discobase
28/03/2025 **Discobase** is a powerful and easy-to-use Node.js package that simplifies the process of creating Discord embeds and buttons for your bot. Whether you are building a community bot, a utility bot, or a game bot, Discobase provides pre-made templates for embeds and buttons, making it incredibly easy to send interactive messages to your server.
## Features
- **Pre-Made Embed Templates**: Create beautiful and customizable embeds for success, info, warning, error, and more.
- **Button Interactions**: Easily create buttons with custom emojis, styles, and actions. Handle button clicks directly in your code without complex event handling.
- **Minimal Code**: Focus on your bots logic and let Discobase handle the boilerplate embed and button creation.
- **Customizable**: Customize embed content, colors, and buttons to suit your specific needs.
## Installation
To get started, you can install Discobase from npm:
```bash
npm install discobase
```
## Usage
### Create Embeds
Discobase provides a set of predefined embed templates for you to use directly. You can customize each template with a message or other options.
**Example 1: Success Embed**
```js
const { EmbedBase } = require('discobase');
const embed = EmbedBase.create('success', 'Your operation was successful!');
channel.send({ embeds: [embed] });
```
**Example 2: Info Embed**
```js
const { EmbedBase } = require('discobase');
const embed = EmbedBase.create('info', 'This is some information!');
channel.send({ embeds: [embed] });
```
## Available Embed Templates
- Success: A green embed used to show successful actions.
- Info: A blue embed for informational messages.
- Warning: An orange embed for warnings.
- Error: A red embed for error messages.
- Neutral: A default white embed for neutral messages.
- Action Required: A purple embed for actions that require user interaction.
**Example: Warning Embed**
```js
const { EmbedBase } = require('discobase');
const embed = EmbedBase.create('warning', 'This is a warning message!');
channel.send({ embeds: [embed] });
```
## Create Buttons
Discobase makes it simple to create buttons with custom actions. Here's how to create a button and send it along with an interaction handler.
**First make sure to pass `client` to `ButtonBase`. You can do it in your main bot file.**
```js
const { ButtonBase } = require('discobase')
ButtonBase.attachListener(client);
```
**Example 1: Creating a Button**
```js
const { ButtonBase } = require('discobase');
const { ButtonStyle } = require('discord.js');
const button = new ButtonBase()
.setEmoji('👍')
.setStyle(ButtonStyle.Primary)
.setCustomId('button1');
const buttonRow = button.build();
await interaction.reply({ components: [buttonRow] });
```
## Button Interaction Handling
You can handle interactions for multiple or single buttons by registering them using `ButtonBase.registerButton()`:
**Single Button Example:**
```js
const { ButtonBase } = require('discobase');
const { ButtonStyle } = require('discord.js');
const button = new ButtonBase()
.setEmoji('👍')
.setStyle(ButtonStyle.Primary)
.setCustomId('button1');
const buttonRow = button.build();
await interaction.reply({ components: [buttonRow] });
ButtonBase.registerButton('button', button);
button.onClick(async (interaction) => {
await interaction.reply('You clicked the first button!');
});
```
## Multiple Buttons
You can also send multiple buttons in the same message. Just create as many buttons as you need and use the Buttons.build() method to add them to a row.
**Example: Multiple Buttons**
```js
const { ButtonBase } = require('discobase');
const { ButtonStyle } = require('discord.js');
const button1 = new ButtonBase()
.setEmoji('👍')
.setStyle(ButtonStyle.Primary)
.setCustomId('button1');
const button2 = new ButtonBase()
.setEmoji('❌')
.setStyle(ButtonStyle.Danger)
.setCustomId('button2');
const buttonRow = ButtonBase.build(button1, button2);
await interaction.reply({ components: [buttonRow] });
ButtonBase.registerButton('button1', button1);
ButtonBase.registerButton('button2', button2);
button1.onClick(async (interaction) => {
await interaction.reply('You clicked the first button!');
});
button2.onClick(async (interaction) => {
await interaction.reply('You clicked the second button!');
});
```
## Contact
If you have any questions or need support, feel free to reach out to us:
- Discord : https://discord.gg/ethical-programmer-s-1188398653530984539
Esta é a pagina inicial.
Sem alterações ainda

345
package-lock.json generated Normal file
View File

@ -0,0 +1,345 @@
{
"name": "discobase",
"version": "1.0.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "discobase",
"version": "1.0.3",
"license": "ISC",
"dependencies": {
"discord.js": "^14.16.3",
"dotenv": "^16.4.5"
}
},
"node_modules/@discordjs/builders": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-1.9.0.tgz",
"integrity": "sha512-0zx8DePNVvQibh5ly5kCEei5wtPBIUbSoE9n+91Rlladz4tgtFbJ36PZMxxZrTEOQ7AHMZ/b0crT/0fCy6FTKg==",
"license": "Apache-2.0",
"dependencies": {
"@discordjs/formatters": "^0.5.0",
"@discordjs/util": "^1.1.1",
"@sapphire/shapeshift": "^4.0.0",
"discord-api-types": "0.37.97",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.4",
"tslib": "^2.6.3"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/builders/node_modules/discord-api-types": {
"version": "0.37.97",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.97.tgz",
"integrity": "sha512-No1BXPcVkyVD4ZVmbNgDKaBoqgeQ+FJpzZ8wqHkfmBnTZig1FcH3iPPersiK1TUIAzgClh2IvOuVUYfcWLQAOA==",
"license": "MIT"
},
"node_modules/@discordjs/collection": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-1.5.3.tgz",
"integrity": "sha512-SVb428OMd3WO1paV3rm6tSjM4wC+Kecaa1EUGX7vc6/fddvw/6lg90z4QtCqm21zvVe92vMMDt9+DkIvjXImQQ==",
"license": "Apache-2.0",
"engines": {
"node": ">=16.11.0"
}
},
"node_modules/@discordjs/formatters": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/@discordjs/formatters/-/formatters-0.5.0.tgz",
"integrity": "sha512-98b3i+Y19RFq1Xke4NkVY46x8KjJQjldHUuEbCqMvp1F5Iq9HgnGpu91jOi/Ufazhty32eRsKnnzS8n4c+L93g==",
"license": "Apache-2.0",
"dependencies": {
"discord-api-types": "0.37.97"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/formatters/node_modules/discord-api-types": {
"version": "0.37.97",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.97.tgz",
"integrity": "sha512-No1BXPcVkyVD4ZVmbNgDKaBoqgeQ+FJpzZ8wqHkfmBnTZig1FcH3iPPersiK1TUIAzgClh2IvOuVUYfcWLQAOA==",
"license": "MIT"
},
"node_modules/@discordjs/rest": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/@discordjs/rest/-/rest-2.4.0.tgz",
"integrity": "sha512-Xb2irDqNcq+O8F0/k/NaDp7+t091p+acb51iA4bCKfIn+WFWd6HrNvcsSbMMxIR9NjcMZS6NReTKygqiQN+ntw==",
"license": "Apache-2.0",
"dependencies": {
"@discordjs/collection": "^2.1.1",
"@discordjs/util": "^1.1.1",
"@sapphire/async-queue": "^1.5.3",
"@sapphire/snowflake": "^3.5.3",
"@vladfrangu/async_event_emitter": "^2.4.6",
"discord-api-types": "0.37.97",
"magic-bytes.js": "^1.10.0",
"tslib": "^2.6.3",
"undici": "6.19.8"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/rest/node_modules/@discordjs/collection": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-2.1.1.tgz",
"integrity": "sha512-LiSusze9Tc7qF03sLCujF5iZp7K+vRNEDBZ86FT9aQAv3vxMLihUvKvpsCWiQ2DJq1tVckopKm1rxomgNUc9hg==",
"license": "Apache-2.0",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/rest/node_modules/discord-api-types": {
"version": "0.37.97",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.97.tgz",
"integrity": "sha512-No1BXPcVkyVD4ZVmbNgDKaBoqgeQ+FJpzZ8wqHkfmBnTZig1FcH3iPPersiK1TUIAzgClh2IvOuVUYfcWLQAOA==",
"license": "MIT"
},
"node_modules/@discordjs/util": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@discordjs/util/-/util-1.1.1.tgz",
"integrity": "sha512-eddz6UnOBEB1oITPinyrB2Pttej49M9FZQY8NxgEvc3tq6ZICZ19m70RsmzRdDHk80O9NoYN/25AqJl8vPVf/g==",
"license": "Apache-2.0",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/ws": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@discordjs/ws/-/ws-1.1.1.tgz",
"integrity": "sha512-PZ+vLpxGCRtmr2RMkqh8Zp+BenUaJqlS6xhgWKEZcgC/vfHLEzpHtKkB0sl3nZWpwtcKk6YWy+pU3okL2I97FA==",
"license": "Apache-2.0",
"dependencies": {
"@discordjs/collection": "^2.1.0",
"@discordjs/rest": "^2.3.0",
"@discordjs/util": "^1.1.0",
"@sapphire/async-queue": "^1.5.2",
"@types/ws": "^8.5.10",
"@vladfrangu/async_event_emitter": "^2.2.4",
"discord-api-types": "0.37.83",
"tslib": "^2.6.2",
"ws": "^8.16.0"
},
"engines": {
"node": ">=16.11.0"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/ws/node_modules/@discordjs/collection": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-2.1.1.tgz",
"integrity": "sha512-LiSusze9Tc7qF03sLCujF5iZp7K+vRNEDBZ86FT9aQAv3vxMLihUvKvpsCWiQ2DJq1tVckopKm1rxomgNUc9hg==",
"license": "Apache-2.0",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/@discordjs/ws/node_modules/discord-api-types": {
"version": "0.37.83",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.83.tgz",
"integrity": "sha512-urGGYeWtWNYMKnYlZnOnDHm8fVRffQs3U0SpE8RHeiuLKb/u92APS8HoQnPTFbnXmY1vVnXjXO4dOxcAn3J+DA==",
"license": "MIT"
},
"node_modules/@sapphire/async-queue": {
"version": "1.5.5",
"resolved": "https://registry.npmjs.org/@sapphire/async-queue/-/async-queue-1.5.5.tgz",
"integrity": "sha512-cvGzxbba6sav2zZkH8GPf2oGk9yYoD5qrNWdu9fRehifgnFZJMV+nuy2nON2roRO4yQQ+v7MK/Pktl/HgfsUXg==",
"license": "MIT",
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/@sapphire/shapeshift": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-4.0.0.tgz",
"integrity": "sha512-d9dUmWVA7MMiKobL3VpLF8P2aeanRTu6ypG2OIaEv/ZHH/SUQ2iHOVyi5wAPjQ+HmnMuL0whK9ez8I/raWbtIg==",
"license": "MIT",
"dependencies": {
"fast-deep-equal": "^3.1.3",
"lodash": "^4.17.21"
},
"engines": {
"node": ">=v16"
}
},
"node_modules/@sapphire/snowflake": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/@sapphire/snowflake/-/snowflake-3.5.3.tgz",
"integrity": "sha512-jjmJywLAFoWeBi1W7994zZyiNWPIiqRRNAmSERxyg93xRGzNYvGjlZ0gR6x0F4gPRi2+0O6S71kOZYyr3cxaIQ==",
"license": "MIT",
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/@types/node": {
"version": "22.9.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz",
"integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==",
"license": "MIT",
"dependencies": {
"undici-types": "~6.19.8"
}
},
"node_modules/@types/ws": {
"version": "8.5.13",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.13.tgz",
"integrity": "sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA==",
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@vladfrangu/async_event_emitter": {
"version": "2.4.6",
"resolved": "https://registry.npmjs.org/@vladfrangu/async_event_emitter/-/async_event_emitter-2.4.6.tgz",
"integrity": "sha512-RaI5qZo6D2CVS6sTHFKg1v5Ohq/+Bo2LZ5gzUEwZ/WkHhwtGTCB/sVLw8ijOkAUxasZ+WshN/Rzj4ywsABJ5ZA==",
"license": "MIT",
"engines": {
"node": ">=v14.0.0",
"npm": ">=7.0.0"
}
},
"node_modules/discord-api-types": {
"version": "0.37.100",
"resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.100.tgz",
"integrity": "sha512-a8zvUI0GYYwDtScfRd/TtaNBDTXwP5DiDVX7K5OmE+DRT57gBqKnwtOC5Ol8z0mRW8KQfETIgiB8U0YZ9NXiCA==",
"license": "MIT"
},
"node_modules/discord.js": {
"version": "14.16.3",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-14.16.3.tgz",
"integrity": "sha512-EPCWE9OkA9DnFFNrO7Kl1WHHDYFXu3CNVFJg63bfU7hVtjZGyhShwZtSBImINQRWxWP2tgo2XI+QhdXx28r0aA==",
"license": "Apache-2.0",
"dependencies": {
"@discordjs/builders": "^1.9.0",
"@discordjs/collection": "1.5.3",
"@discordjs/formatters": "^0.5.0",
"@discordjs/rest": "^2.4.0",
"@discordjs/util": "^1.1.1",
"@discordjs/ws": "1.1.1",
"@sapphire/snowflake": "3.5.3",
"discord-api-types": "0.37.100",
"fast-deep-equal": "3.1.3",
"lodash.snakecase": "4.1.1",
"tslib": "^2.6.3",
"undici": "6.19.8"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/discordjs/discord.js?sponsor"
}
},
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
"license": "MIT"
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"license": "MIT"
},
"node_modules/lodash.snakecase": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz",
"integrity": "sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==",
"license": "MIT"
},
"node_modules/magic-bytes.js": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.10.0.tgz",
"integrity": "sha512-/k20Lg2q8LE5xiaaSkMXk4sfvI+9EGEykFS4b0CHHGWqDYU0bGUFSwchNOMA56D7TCs9GwVTkqe9als1/ns8UQ==",
"license": "MIT"
},
"node_modules/ts-mixer": {
"version": "6.0.4",
"resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.4.tgz",
"integrity": "sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA==",
"license": "MIT"
},
"node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/undici": {
"version": "6.19.8",
"resolved": "https://registry.npmjs.org/undici/-/undici-6.19.8.tgz",
"integrity": "sha512-U8uCCl2x9TK3WANvmBavymRzxbfFYG+tAu+fgx3zxQy3qdagQqBLwJVrdyO1TBfUXvfKveMKJZhpvUYoOjM+4g==",
"license": "MIT",
"engines": {
"node": ">=18.17"
}
},
"node_modules/undici-types": {
"version": "6.19.8",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
"license": "MIT"
},
"node_modules/ws": {
"version": "8.18.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

23
package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "discobase",
"version": "1.0.3",
"description": "Discobase is a powerful Node.js package for creating customizable Discord buttons and embed templates. It simplifies the process of sending Discord embeds and buttons with dynamic interaction handling, making it easier to create engaging Discord bot experiences. Features include pre-made embed templates for success, info, warning, error messages, as well as the ability to easily manage button interactions with customizable styles, emojis, and IDs.",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"discord",
"buttons",
"embeds",
"discord.js",
"interactions",
"templates",
"nodejs"
],
"author": "Ethical Programmer",
"license": "MIT",
"dependencies": {
"discord.js": "^14.0.0"
}
}

103
src/ButtonBase.js Normal file
View File

@ -0,0 +1,103 @@
const { ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');
const EventEmitter = require('events');
class ButtonBase extends EventEmitter {
constructor() {
super();
this.button = new ButtonBuilder();
}
setEmoji(emoji) {
this.button.setEmoji(emoji);
return this;
}
setStyle(style) {
this.button.setStyle(ButtonStyle[style] || ButtonStyle.Primary);
return this;
}
setCustomId(customId) {
this.button.setCustomId(customId);
this.customId = customId; // Store the custom ID locally for interaction handling
return this;
}
/**
* Attach an onClick listener for the button's interaction
* @param {function} callback - The callback function to handle button click interaction
* @returns {ButtonBase} - Returns the ButtonBase instance for chaining
*/
onClick(callback) {
this.on('click', callback);
return this;
}
/**
* Build the button and return it inside an action row (for single button).
* @returns {ActionRowBuilder} - Returns the ActionRowBuilder with the button
*/
build() {
return new ActionRowBuilder().addComponents(this.button);
}
/**
* Handle the button interaction. This method is responsible for automatically
* listening to interactions and triggering the appropriate event.
* @param {Interaction} interaction - The interaction object from discord.js
*/
async handleInteraction(interaction) {
if (interaction.isButton() && interaction.customId === this.customId) {
this.emit('click', interaction);
}
}
/**
* Automatically listen for interactions from the provided client.
* @param {Client} client - The discord.js client
*/
static attachListener(client) {
client.on('interactionCreate', async (interaction) => {
if (interaction.isButton()) {
const button = ButtonBase.getButtonByCustomId(interaction.customId);
if (button) {
await button.handleInteraction(interaction);
}
}
});
}
/**
* Store buttons by their customId for interaction lookup.
* @param {string} customId - The customId of the button
* @param {ButtonBase} button - The button instance
*/
static registerButton(customId, button) {
if (!ButtonBase.buttonRegistry) {
ButtonBase.buttonRegistry = {};
}
ButtonBase.buttonRegistry[customId] = button;
}
/**
* Get a button instance by its customId.
* @param {string} customId - The customId of the button
* @returns {ButtonBase|null} - Returns the button instance or null
*/
static getButtonByCustomId(customId) {
return ButtonBase.buttonRegistry ? ButtonBase.buttonRegistry[customId] : null;
}
/**
* Build and send multiple buttons in one action row.
* @param {...ButtonBase} buttons - The ButtonBase instances to be added to the action row
* @returns {ActionRowBuilder} - Returns an ActionRowBuilder with all buttons
*/
static build(...buttons) {
const row = new ActionRowBuilder();
buttons.forEach(button => row.addComponents(button.button));
return row;
}
}
module.exports = ButtonBase;

50
src/EmbedBase.js Normal file
View File

@ -0,0 +1,50 @@
// src/EmbedBase.js
const successEmbed = require('./templates/successEmbed');
const infoEmbed = require('./templates/infoEmbed');
const warningEmbed = require('./templates/warningEmbed');
const errorEmbed = require('./templates/errorEmbed');
const neutralEmbed = require('./templates/neutralEmbed');
const actionRequiredEmbed = require('./templates/actionRequiredEmbed');
const { createButton } = require('./utils/buttonUtil')
class EmbedBase {
static create(type, message, options = {}) {
switch (type.toLowerCase()) {
case 'success':
return successEmbed(message);
case 'info':
return infoEmbed(message);
case 'warning':
return warningEmbed(message);
case 'error':
return errorEmbed(message);
case 'neutral':
return neutralEmbed(message);
case 'actionrequired':
return actionRequiredEmbed(message);
default:
throw new Error('Invalid embed type');
}
}
/**
* Creates an embed with buttons
* @param {string} type - Type of embed.
* @param {string} message - The message to display in embed.
* @param {Array} buttons - Array of button configurations.
* @returns {Object} - Embed with buttons.
*/
static createWithButtons(type, message, buttons = []) {
// First, create the embed based on the type
const embed = EmbedBase.create(type, message);
// Create buttons using utility function
const actionRows = buttons.map(button => createButton(button.label, button.customId, button.style, button.emoji));
return { embed, components: actionRows };
}
}
module.exports = EmbedBase;

4
src/index.js Normal file
View File

@ -0,0 +1,4 @@
const EmbedBase = require('./EmbedBase');
const ButtonBase = require('./ButtonBase');
module.exports = { EmbedBase, ButtonBase };

View File

@ -0,0 +1,9 @@
const { EmbedBuilder } = require('discord.js');
function actionRequiredEmbed(message) {
return new EmbedBuilder()
.setColor('Orange')
.setDescription(`\`⚠️\` ${message}\nPlease take action!`);
}
module.exports = actionRequiredEmbed;

View File

@ -0,0 +1,46 @@
/**
* Changes made by Jack on 2025-03-23 11:45:00
*
* CHANGELOG:
* - Added comprehensive JSDoc comments for better IDE support and documentation
* - Improved function parameter documentation
* - Added examples of usage
* - Enhanced error message formatting
* - Added color constant for better maintainability
*/
const { EmbedBuilder } = require('discord.js');
/**
* Error color code for consistent styling across error embeds
* Using hex code instead of named color for more precise control
*/
const ERROR_COLOR = '#FF0000';
/**
* Creates a standardized Discord error embed with consistent styling.
*
* This utility function generates a pre-styled Discord embed meant for
* displaying error messages to users. The embed uses a red color theme
* and prefixes the message with an "❌" emoji for visual indication.
*
* @param {string} message - The error message to display in the embed
* @returns {EmbedBuilder} A configured Discord.js EmbedBuilder instance
*
* @example
* // Basic usage
* const embed = errorEmbed('Invalid command parameters');
* interaction.reply({ embeds: [embed] });
*
* @example
* // With dynamic content
* const embed = errorEmbed(`User ${user.tag} not found in database`);
* message.channel.send({ embeds: [embed] });
*/
function errorEmbed(message) {
return new EmbedBuilder()
.setColor(ERROR_COLOR)
.setDescription(`\`\` | ${message}`);
}
module.exports = errorEmbed;

View File

@ -0,0 +1,9 @@
const { EmbedBuilder } = require('discord.js');
function infoEmbed(message) {
return new EmbedBuilder()
.setColor('Blue')
.setDescription(`\`\` | ${message}`);
}
module.exports = infoEmbed;

View File

@ -0,0 +1,9 @@
const { EmbedBuilder } = require('discord.js');
function neutralEmbed(message) {
return new EmbedBuilder()
.setColor('Grey')
.setDescription(message);
}
module.exports = neutralEmbed;

View File

@ -0,0 +1,9 @@
const { EmbedBuilder } = require('discord.js');
function successEmbed(message) {
return new EmbedBuilder()
.setColor('Green')
.setDescription(`\`\` | ${message}`);
}
module.exports = successEmbed;

View File

@ -0,0 +1,9 @@
const { EmbedBuilder } = require('discord.js');
function warningEmbed(message) {
return new EmbedBuilder()
.setColor('Yellow')
.setDescription(`\`⚠️\` | ${message}`);
}
module.exports = warningEmbed;

24
src/utils/buttonUtil.js Normal file
View File

@ -0,0 +1,24 @@
const { ButtonBuilder, ActionRowBuilder, ButtonStyle } = require('discord.js');
/**
* Creates a button
* @param {string} label - Button text.
* @param {string} customId - Custom ID to identify the button.
* @param {string} style - Button style (primary, secondary, success, danger, link).
* @param {string} emoji - Emoji to add to the button (optional).
* @returns {ActionRowBuilder} - Returns ActionRow with button.
*/
function createButton(label, customId, style = 'primary', emoji = '') {
const button = new ButtonBuilder()
.setLabel(label)
.setCustomId(customId)
.setStyle(ButtonStyle[style] || ButtonStyle.Primary);
if (emoji) {
button.setEmoji(emoji);
}
return new ActionRowBuilder().addComponents(button);
}
module.exports = { createButton };