mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
cleanup cleanup cleanup on isle dd (#2792)
* cleanup cleanup cleanup on isle dd * fix: rest manager import in test
This commit is contained in:
@@ -7,24 +7,24 @@ sidebar_position: 2
|
||||
Currently, you probably have something like this in your code:
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno.js");
|
||||
const Discord = require('discordeno.js')
|
||||
// Ideally you should move to an `.env` file
|
||||
const config = require("./config.json");
|
||||
const config = require('./config.json')
|
||||
|
||||
const bot = Discord.createBot({
|
||||
events: {
|
||||
messageCreate(client, message) {
|
||||
if (message.content === "!ping") {
|
||||
client.helpers.sendMessage(message.channelId, { content: "pong" });
|
||||
if (message.content === '!ping') {
|
||||
client.helpers.sendMessage(message.channelId, { content: 'pong' })
|
||||
}
|
||||
},
|
||||
},
|
||||
intents: Discord.Intents.Guilds | Discord.Intents.GuildMessages,
|
||||
token: config.token,
|
||||
});
|
||||
const client = Discord.enableCachePlugin(bot, {});
|
||||
})
|
||||
const client = Discord.enableCachePlugin(bot, {})
|
||||
|
||||
Discord.startBot(client);
|
||||
Discord.startBot(client)
|
||||
```
|
||||
|
||||
Of course, if you add more and more commands and as your code base grows, you can lose track very quickly.
|
||||
@@ -50,12 +50,12 @@ To avoid this, it is recommended to store the commands in separate folders divid
|
||||
the [nodejs template](https://github.com/discordeno/discordeno/tree/main/template)**
|
||||
|
||||
```js
|
||||
const CommandManager = require("./template/Managers/CommandManager.js");
|
||||
const manager = new CommandManager({});
|
||||
manager.load({ plugin: true }); // Load the commands
|
||||
client.commands = manager;
|
||||
const CommandManager = require('./template/Managers/CommandManager.js')
|
||||
const manager = new CommandManager({})
|
||||
manager.load({ plugin: true }) // Load the commands
|
||||
client.commands = manager
|
||||
|
||||
client.commands.cache.get("ping"); // Get the `ping` command
|
||||
client.commands.cache.get('ping') // Get the `ping` command
|
||||
```
|
||||
|
||||
The Manager will automatically iterate through all files in the folder and then load them into the cache property, which
|
||||
@@ -77,16 +77,16 @@ Currently checks for permissions, cooldowns, and rate limits are not covered, bu
|
||||
|
||||
```js
|
||||
module.exports = async (client, message) => {
|
||||
client.commands.isCommand(message);
|
||||
};
|
||||
client.commands.isCommand(message)
|
||||
}
|
||||
```
|
||||
|
||||
### Interaction Create Event:
|
||||
|
||||
```js
|
||||
module.exports = async (client, interaction) => {
|
||||
client.commands.isInteraction(interaction);
|
||||
};
|
||||
client.commands.isInteraction(interaction)
|
||||
}
|
||||
```
|
||||
|
||||
You can also customize the `isCommand` function to your use case.
|
||||
|
||||
@@ -7,28 +7,28 @@ sidebar_position: 2
|
||||
In order to process certain events, you must provide the Discordeno client with functions for these events.
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno");
|
||||
const config = require("./config.json");
|
||||
const Discord = require('discordeno')
|
||||
const config = require('./config.json')
|
||||
|
||||
const client = Discord.createBot({
|
||||
events: {
|
||||
ready(client, payload) {
|
||||
console.log(`Successfully connected Shard ${payload.shardId} to the gateway`);
|
||||
console.log(`Successfully connected Shard ${payload.shardId} to the gateway`)
|
||||
},
|
||||
|
||||
async messageCreate(client, message) {
|
||||
if (message.content === "!ping") {
|
||||
await client.helpers.sendMessage(message.channelId, { content: "pong" });
|
||||
if (message.content === '!ping') {
|
||||
await client.helpers.sendMessage(message.channelId, { content: 'pong' })
|
||||
}
|
||||
|
||||
console.log(`Received message: ${message.content || message.embeds}`);
|
||||
console.log(`Received message: ${message.content || message.embeds}`)
|
||||
},
|
||||
},
|
||||
intents: ["Guilds", "GuildMessages"],
|
||||
intents: ['Guilds', 'GuildMessages'],
|
||||
token: config.token,
|
||||
});
|
||||
})
|
||||
|
||||
Discord.startBot(client);
|
||||
Discord.startBot(client)
|
||||
```
|
||||
|
||||
As you listen to more and more events, the functions code grows along with them, so you can quickly lose track.
|
||||
@@ -52,42 +52,42 @@ Ready Event:
|
||||
module.exports = (client, payload) => {
|
||||
if (payload.shardId + 1 === client.gateway.maxShards) {
|
||||
// All Shards are ready
|
||||
console.log(`Successfully connected to the gateway as ${payload.user.username}#${payload.user.discriminator}`);
|
||||
console.log(`Successfully connected to the gateway as ${payload.user.username}#${payload.user.discriminator}`)
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## Load your Events
|
||||
|
||||
```js
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const resolveFolder = (folderName) => path.resolve(__dirname, ".", folderName);
|
||||
const resolveFolder = (folderName) => path.resolve(__dirname, '.', folderName)
|
||||
|
||||
class EventManager {
|
||||
constructor(client) {
|
||||
this.cache = new Map();
|
||||
this._events = {};
|
||||
this.cache = new Map()
|
||||
this._events = {}
|
||||
}
|
||||
|
||||
load(options = {}) {
|
||||
const eventsFolder = resolveFolder("../events");
|
||||
const eventsFolder = resolveFolder('../events')
|
||||
fs.readdirSync(eventsFolder).map(async (file) => {
|
||||
if (!file.endsWith(".js")) return;
|
||||
if (!file.endsWith('.js')) return
|
||||
|
||||
const fileName = path.join(eventsFolder, file);
|
||||
const event = require(fileName);
|
||||
const eventName = file.split(".")[0];
|
||||
const fileName = path.join(eventsFolder, file)
|
||||
const event = require(fileName)
|
||||
const eventName = file.split('.')[0]
|
||||
|
||||
this._events[`${eventName}`] = event;
|
||||
});
|
||||
this._events[`${eventName}`] = event
|
||||
})
|
||||
|
||||
return this._events;
|
||||
return this._events
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = EventManager;
|
||||
module.exports = EventManager
|
||||
```
|
||||
|
||||
The code above, which can also be found in the
|
||||
@@ -98,19 +98,19 @@ In order to let the client know which events should be processed, you need to pa
|
||||
`createBot<options>.events` object.
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno");
|
||||
const config = require("./config.json");
|
||||
const Discord = require('discordeno')
|
||||
const config = require('./config.json')
|
||||
|
||||
const EventManager = require("./Managers/EventManager.js");
|
||||
const events = new EventManager({});
|
||||
const EventManager = require('./Managers/EventManager.js')
|
||||
const events = new EventManager({})
|
||||
|
||||
const client = Discord.createBot({
|
||||
events: events.load({}),
|
||||
intents: ["Guilds", "GuildMessages"],
|
||||
intents: ['Guilds', 'GuildMessages'],
|
||||
token: config.token,
|
||||
});
|
||||
})
|
||||
|
||||
Discord.startBot(client);
|
||||
Discord.startBot(client)
|
||||
```
|
||||
|
||||
Moreover, you can customize the `EventManager` and add more functionality to it and make it exactly fit your needs or
|
||||
|
||||
@@ -24,14 +24,14 @@ Sometimes it's important to listen to events, in order to get informed of change
|
||||
This file should be called `messageCreate.js`.
|
||||
|
||||
```js
|
||||
const Message = require("./structures/Message");
|
||||
const Message = require('./structures/Message')
|
||||
|
||||
module.exports = async (client, payload) => {
|
||||
const message = client.messages.forge(payload);
|
||||
const message = client.messages.forge(payload)
|
||||
|
||||
if (message.author.bot) return;
|
||||
if (message.content === "!ping") return await message.reply("pong");
|
||||
};
|
||||
if (message.author.bot) return
|
||||
if (message.content === '!ping') return await message.reply('pong')
|
||||
}
|
||||
```
|
||||
|
||||
### Interaction Event
|
||||
@@ -39,13 +39,13 @@ module.exports = async (client, payload) => {
|
||||
This file should be called `interactionCreate.js`.
|
||||
|
||||
```js
|
||||
const Interaction = require("./structures/Interaction");
|
||||
const Interaction = require('./structures/Interaction')
|
||||
|
||||
module.exports = async (client, payload) => {
|
||||
const interaction = client.interactions.forge(payload);
|
||||
const interaction = client.interactions.forge(payload)
|
||||
|
||||
if (interaction.data.name === "ping") return await interaction.reply({ content: "pong" });
|
||||
};
|
||||
if (interaction.data.name === 'ping') return await interaction.reply({ content: 'pong' })
|
||||
}
|
||||
```
|
||||
|
||||
### Ready Event
|
||||
@@ -62,14 +62,14 @@ a `shard` becomes ready.
|
||||
In order to fire the "real event" a small code snippet has to be added to the `ready` Event.
|
||||
|
||||
```js
|
||||
const User = require("../Structures/User");
|
||||
const User = require('../Structures/User')
|
||||
|
||||
module.exports = async (client, payload) => {
|
||||
client.user = client.users.forge(payload.user);
|
||||
client.user = client.users.forge(payload.user)
|
||||
|
||||
if (payload.shardId + 1 === client.gateway.maxShards) {
|
||||
// All Shards are ready
|
||||
console.log(`Successfully connected to the gateway as ${client.user.tag}`);
|
||||
console.log(`Successfully connected to the gateway as ${client.user.tag}`)
|
||||
}
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
@@ -22,27 +22,27 @@ We have a pre-made class for collectors which you can find
|
||||
[here](https://github.com/meister03/discordeno.js/blob/master/Util/Collectors.js).
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno.js");
|
||||
const filter = (m) => m.data?.customId === "warn_modal" && m.user.id === interaction.user.id;
|
||||
const listener = client.eventListener; // When the eventListener property is named different
|
||||
const collector = new Discord.Collector("interactionCreate", {
|
||||
const Discord = require('discordeno.js')
|
||||
const filter = (m) => m.data?.customId === 'warn_modal' && m.user.id === interaction.user.id
|
||||
const listener = client.eventListener // When the eventListener property is named different
|
||||
const collector = new Discord.Collector('interactionCreate', {
|
||||
client: client,
|
||||
timeout: 60000,
|
||||
filter,
|
||||
max: 20,
|
||||
listener,
|
||||
});
|
||||
collector.on("collect", (m) => {
|
||||
const interaction = client.interactions.forge(m);
|
||||
})
|
||||
collector.on('collect', (m) => {
|
||||
const interaction = client.interactions.forge(m)
|
||||
// Stop Collector
|
||||
// collector.stop();
|
||||
});
|
||||
})
|
||||
|
||||
// Fires on a timeout, when the collector has reached the max amount of interactions or when it has been closed
|
||||
collector.on("end", (collected) => {
|
||||
collector.on('end', (collected) => {
|
||||
// Map of Collected Interactions
|
||||
console.log(collected);
|
||||
});
|
||||
console.log(collected)
|
||||
})
|
||||
```
|
||||
|
||||
As you can see, this opens up many possibilities. You can listen to any event and get the interaction you need.
|
||||
|
||||
@@ -82,20 +82,20 @@ component you want to use.
|
||||
```js
|
||||
class ActionRow {
|
||||
constructor(options = {}) {
|
||||
this.type = 1;
|
||||
this.type = 1
|
||||
}
|
||||
|
||||
setComponents(...components) {
|
||||
this.components = components;
|
||||
return this;
|
||||
this.components = components
|
||||
return this
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```js
|
||||
const button = new Button();
|
||||
const button2 = new Button();
|
||||
const actionRow = new ActionRow().setComponents(button, button2);
|
||||
const button = new Button()
|
||||
const button2 = new Button()
|
||||
const actionRow = new ActionRow().setComponents(button, button2)
|
||||
```
|
||||
|
||||
This code will obviously not work because it's a missing a lot required of data. The other reason is that we can't send
|
||||
@@ -107,34 +107,21 @@ We have a pre-made class for components which you can find
|
||||
### Button
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno.js");
|
||||
const message = client.messages.forge(rawMessage);
|
||||
const Discord = require('discordeno.js')
|
||||
const message = client.messages.forge(rawMessage)
|
||||
|
||||
const button = new Discord.Component()
|
||||
.setType("BUTTON")
|
||||
.setStyle("LINK")
|
||||
.setLabel("Click me!")
|
||||
.setUrl("https://google.com")
|
||||
.toJSON();
|
||||
const button = new Discord.Component().setType('BUTTON').setStyle('LINK').setLabel('Click me!').setUrl('https://google.com').toJSON()
|
||||
|
||||
// Button with raw types
|
||||
const button2 = new Discord.Component()
|
||||
.setType(2)
|
||||
.setStyle(4)
|
||||
.setLabel("DO NOT CLICK")
|
||||
.setCustomId("12345")
|
||||
.toJSON();
|
||||
const button2 = new Discord.Component().setType(2).setStyle(4).setLabel('DO NOT CLICK').setCustomId('12345').toJSON()
|
||||
|
||||
const actionRow = new Discord.Component()
|
||||
.setType("ACTION_ROW")
|
||||
.setComponents(button, button2)
|
||||
.toJSON();
|
||||
const actionRow = new Discord.Component().setType('ACTION_ROW').setComponents(button, button2).toJSON()
|
||||
|
||||
// Message to send
|
||||
const messageOptions = { content: "hello", components: [actionRow] };
|
||||
const messageOptions = { content: 'hello', components: [actionRow] }
|
||||
|
||||
// await client.helpers.sendMessage(channelId, messageOptions); // Do it the raw way
|
||||
message.channel.send(messageOptions); // Do it with the structure
|
||||
message.channel.send(messageOptions) // Do it with the structure
|
||||
```
|
||||
|
||||
As you can see, for simplicity you can use strings instead of numbers (types), which are hard to remember.
|
||||
@@ -142,79 +129,76 @@ As you can see, for simplicity you can use strings instead of numbers (types), w
|
||||
### Select Menu
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno.js");
|
||||
const message = client.messages.forge(rawMessage);
|
||||
const Discord = require('discordeno.js')
|
||||
const message = client.messages.forge(rawMessage)
|
||||
|
||||
const selectMenu = new Discord.Component()
|
||||
.setType("SELECT_MENU")
|
||||
.setCustomId("12345")
|
||||
.setType('SELECT_MENU')
|
||||
.setCustomId('12345')
|
||||
.setOptions([
|
||||
{
|
||||
label: "Option 1",
|
||||
value: "1",
|
||||
label: 'Option 1',
|
||||
value: '1',
|
||||
description: `This is option 1`,
|
||||
},
|
||||
{
|
||||
label: "Option 2",
|
||||
value: "2",
|
||||
label: 'Option 2',
|
||||
value: '2',
|
||||
description: `This is option 2`,
|
||||
},
|
||||
{
|
||||
label: "Default Option",
|
||||
value: "3",
|
||||
label: 'Default Option',
|
||||
value: '3',
|
||||
description: `Default option...`,
|
||||
default: true,
|
||||
},
|
||||
])
|
||||
.setPlaceholder("Select an option")
|
||||
.toJSON();
|
||||
.setPlaceholder('Select an option')
|
||||
.toJSON()
|
||||
|
||||
const actionRow = new Discord.Component()
|
||||
.setType("ACTION_ROW")
|
||||
.setComponents(selectMenu)
|
||||
.toJSON();
|
||||
const actionRow = new Discord.Component().setType('ACTION_ROW').setComponents(selectMenu).toJSON()
|
||||
|
||||
const messageOptions = { content: "hello", components: [actionRow] };
|
||||
const messageOptions = { content: 'hello', components: [actionRow] }
|
||||
|
||||
// await client.helpers.sendMessage(channelId, messageOptions); // Do it the raw way
|
||||
message.channel.send(messageOptions); // Do it with the structure
|
||||
message.channel.send(messageOptions) // Do it with the structure
|
||||
```
|
||||
|
||||
### Text Input
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno.js");
|
||||
const interaction = client.messages.forge(rawInteraction);
|
||||
const Discord = require('discordeno.js')
|
||||
const interaction = client.messages.forge(rawInteraction)
|
||||
|
||||
const textInput = new Component()
|
||||
.setType("TEXT_INPUT")
|
||||
.setStyle("SHORT")
|
||||
.setCustomId("t1")
|
||||
.setLabel("User ID")
|
||||
.setPlaceholder("User ID")
|
||||
.setType('TEXT_INPUT')
|
||||
.setStyle('SHORT')
|
||||
.setCustomId('t1')
|
||||
.setLabel('User ID')
|
||||
.setPlaceholder('User ID')
|
||||
.setRequired(true)
|
||||
.setMaxLength(20)
|
||||
.setMinLength(1)
|
||||
.toJSON();
|
||||
.toJSON()
|
||||
|
||||
const textInput2 = new Component()
|
||||
.setType("TEXT_INPUT")
|
||||
.setStyle("PARAGRAPH")
|
||||
.setCustomId("t2")
|
||||
.setLabel("Reason")
|
||||
.setPlaceholder("Reason for Ban")
|
||||
.setType('TEXT_INPUT')
|
||||
.setStyle('PARAGRAPH')
|
||||
.setCustomId('t2')
|
||||
.setLabel('Reason')
|
||||
.setPlaceholder('Reason for Ban')
|
||||
.setRequired(false)
|
||||
.setMaxLength(300)
|
||||
.toJSON();
|
||||
.toJSON()
|
||||
|
||||
const actionRow = new Component().setType("ACTION_ROW").setComponents(textInput).toJSON();
|
||||
const actionRow2 = new Component().setType("ACTION_ROW").setComponents(textInput2).toJSON();
|
||||
const actionRow = new Component().setType('ACTION_ROW').setComponents(textInput).toJSON()
|
||||
const actionRow2 = new Component().setType('ACTION_ROW').setComponents(textInput2).toJSON()
|
||||
|
||||
interaction.popupModal({
|
||||
customId: "ban_modal",
|
||||
title: "Ban User",
|
||||
customId: 'ban_modal',
|
||||
title: 'Ban User',
|
||||
components: [actionRow, actionRow2],
|
||||
});
|
||||
})
|
||||
```
|
||||
|
||||
### Receive Interactions
|
||||
|
||||
@@ -11,14 +11,14 @@ Imagine you have a channel object to which you want to send a message.
|
||||
```js
|
||||
const data = {
|
||||
id: 806947972004839444n,
|
||||
name: "spam-and-bots",
|
||||
};
|
||||
name: 'spam-and-bots',
|
||||
}
|
||||
```
|
||||
|
||||
The recommended way would be:
|
||||
|
||||
```js
|
||||
await client.helpers.sendMessage(data.id, { content: "hello" });
|
||||
await client.helpers.sendMessage(data.id, { content: 'hello' })
|
||||
```
|
||||
|
||||
However, you probably want to use something shorter, such as the following:
|
||||
@@ -26,13 +26,13 @@ However, you probably want to use something shorter, such as the following:
|
||||
```js
|
||||
class Channel {
|
||||
constructor(client, data) {
|
||||
this.client = client;
|
||||
this.id = data.id;
|
||||
this.name = data.name;
|
||||
this.client = client
|
||||
this.id = data.id
|
||||
this.name = data.name
|
||||
}
|
||||
|
||||
async send(options) {
|
||||
return await this.client.helpers.sendMessage(this.id, options);
|
||||
return await this.client.helpers.sendMessage(this.id, options)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -40,8 +40,8 @@ class Channel {
|
||||
Now you can use the `.send()` method on the channel object without using such a long code:
|
||||
|
||||
```js
|
||||
const channel = new Channel(client, data);
|
||||
await channel.send({ content: "hello" });
|
||||
const channel = new Channel(client, data)
|
||||
await channel.send({ content: 'hello' })
|
||||
```
|
||||
|
||||
Moreover, you can modify the `.send()` method to better suit your use case e.g not send the message if the channel is
|
||||
@@ -74,22 +74,22 @@ construct the client for following the Guide
|
||||
**Using the Structures:**
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno.js");
|
||||
const client = new Discord.Client(clientOptions, cacheOptions); //See the Readme above
|
||||
Discord.startBot(client);
|
||||
const guild = client.guilds.forge(guildData);
|
||||
const channel = guild.channels.forge(channelData);
|
||||
const role = guild.roles.forge(roleData);
|
||||
const member = guild.members.forge(memberData);
|
||||
const user = guild.users.forge(userData);
|
||||
const message = guild.messages.forge(messageData);
|
||||
const interaction = guild.interactions.forge(interactionData);
|
||||
const emoji = guild.emojis.forge(emojiData);
|
||||
const Discord = require('discordeno.js')
|
||||
const client = new Discord.Client(clientOptions, cacheOptions) //See the Readme above
|
||||
Discord.startBot(client)
|
||||
const guild = client.guilds.forge(guildData)
|
||||
const channel = guild.channels.forge(channelData)
|
||||
const role = guild.roles.forge(roleData)
|
||||
const member = guild.members.forge(memberData)
|
||||
const user = guild.users.forge(userData)
|
||||
const message = guild.messages.forge(messageData)
|
||||
const interaction = guild.interactions.forge(interactionData)
|
||||
const emoji = guild.emojis.forge(emojiData)
|
||||
|
||||
const webhook = new Discord.Webhook(client, webhookData);
|
||||
const embed = new Discord.Embed(embedData); // embedData is optional
|
||||
const component = new Discord.Component(componentData); // componentData is optional
|
||||
const collection = new Discord.Collection();
|
||||
const webhook = new Discord.Webhook(client, webhookData)
|
||||
const embed = new Discord.Embed(embedData) // embedData is optional
|
||||
const component = new Discord.Component(componentData) // componentData is optional
|
||||
const collection = new Discord.Collection()
|
||||
```
|
||||
|
||||
Some popular methods have been added to the structures so that you can use them without having to come up with your own.
|
||||
|
||||
@@ -32,7 +32,7 @@ Now we have created a class which we can use to create embeds. But we can't just
|
||||
So we need an additional method which will convert the data from the class to the correct format.
|
||||
|
||||
```js
|
||||
class Embed(){
|
||||
class Embed(){
|
||||
constructor() {}
|
||||
|
||||
setTitle(title) {
|
||||
@@ -50,10 +50,10 @@ class Embed(){
|
||||
Wow, now you can create a embed and send it to Discord.
|
||||
|
||||
```js
|
||||
const Channel = require("./structures/Channel"); // Path to structure
|
||||
const Channel = require('./structures/Channel') // Path to structure
|
||||
|
||||
const channel = new Channel(client, data);
|
||||
await channel.send({ embeds: [embed] });
|
||||
const channel = new Channel(client, data)
|
||||
await channel.send({ embeds: [embed] })
|
||||
```
|
||||
|
||||
You probably want more methods which you can use to create embeds.
|
||||
@@ -62,36 +62,36 @@ You probably want more methods which you can use to create embeds.
|
||||
### Using the Embed Structure:
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno.js");
|
||||
const Discord = require('discordeno.js')
|
||||
|
||||
const channel = client.channels.forge(channelData);
|
||||
const channel = client.channels.forge(channelData)
|
||||
const showCaseEmbed = new Discord.Embed()
|
||||
.setColor(0x00AE86)
|
||||
.setTitle("A Random Title")
|
||||
.setURL("https://github.com/discordeno")
|
||||
.setColor(0x00ae86)
|
||||
.setTitle('A Random Title')
|
||||
.setURL('https://github.com/discordeno')
|
||||
.setAuthor({
|
||||
name: "Author name",
|
||||
iconUrl: "https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png",
|
||||
url: "https://github.com/discordeno",
|
||||
name: 'Author name',
|
||||
iconUrl: 'https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png',
|
||||
url: 'https://github.com/discordeno',
|
||||
})
|
||||
.setDescription("A Random Description")
|
||||
.setThumbnail("https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png")
|
||||
.setDescription('A Random Description')
|
||||
.setThumbnail('https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png')
|
||||
.addFields(
|
||||
{ name: "Field 1 Name", value: "Normal Field Value" },
|
||||
{ name: "\u200B", value: "\u200B" },
|
||||
{ name: "Field 2 Name", value: "Inline Field Value", inline: true },
|
||||
{ name: "Field 3 Name", value: "Inline Field Value", inline: true },
|
||||
{ name: 'Field 1 Name', value: 'Normal Field Value' },
|
||||
{ name: '\u200B', value: '\u200B' },
|
||||
{ name: 'Field 2 Name', value: 'Inline Field Value', inline: true },
|
||||
{ name: 'Field 3 Name', value: 'Inline Field Value', inline: true },
|
||||
)
|
||||
.addField({ name: "Field 4", value: "Field Value" })
|
||||
.setImage("https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png")
|
||||
.addField({ name: 'Field 4', value: 'Field Value' })
|
||||
.setImage('https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png')
|
||||
.setTimestamp()
|
||||
.setFooter({
|
||||
text: "A Footer Text",
|
||||
iconUrl: "https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png",
|
||||
text: 'A Footer Text',
|
||||
iconUrl: 'https://raw.githubusercontent.com/discordeno/discordeno/main/site/static/img/logo.png',
|
||||
})
|
||||
.toJSON();
|
||||
.toJSON()
|
||||
|
||||
await channel.send({ embeds: [showCaseEmbed] });
|
||||
await channel.send({ embeds: [showCaseEmbed] })
|
||||
```
|
||||
|
||||
### Embed Limits:
|
||||
|
||||
@@ -9,7 +9,7 @@ As previously mentioned, Discordeno was built with as few classes as possible, t
|
||||
For example, you cannot execute functions on objects.
|
||||
|
||||
```diff
|
||||
- message.channel.send({content: "hello"})
|
||||
- message.channel.send({content: "hello"})
|
||||
+ client.helpers.sendMessage(message.channel.id, {content: "hello"})
|
||||
```
|
||||
|
||||
|
||||
@@ -87,9 +87,9 @@ Example:
|
||||
|
||||
```js
|
||||
class Command {
|
||||
static name = "ping";
|
||||
static aliases = ["pong"];
|
||||
static botPermission = ["SEND_EMBED_LINKS"];
|
||||
static name = 'ping'
|
||||
static aliases = ['pong']
|
||||
static botPermission = ['SEND_EMBED_LINKS']
|
||||
|
||||
run(message, args) {
|
||||
// do something
|
||||
@@ -106,17 +106,17 @@ by each command. Extending the class makes this extra step obsolete.
|
||||
```js
|
||||
class BaseCommand {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
this.basePermission = ["SEND_EMBED_LINKS"];
|
||||
this.client = client
|
||||
this.basePermission = ['SEND_EMBED_LINKS']
|
||||
}
|
||||
}
|
||||
|
||||
class Command extends BaseCommand {
|
||||
static name = "ping";
|
||||
static aliases = ["pong"];
|
||||
static name = 'ping'
|
||||
static aliases = ['pong']
|
||||
|
||||
constructor(data) {
|
||||
super(data);
|
||||
super(data)
|
||||
}
|
||||
|
||||
run(message, args) {
|
||||
|
||||
@@ -23,20 +23,20 @@ Create a file named `config.json` in your project folder and insert the followin
|
||||
Open the `index.js` file which you have created earlier and then insert the following content:
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno");
|
||||
const config = require("./config.json");
|
||||
const Discord = require('discordeno')
|
||||
const config = require('./config.json')
|
||||
|
||||
const client = Discord.createBot({
|
||||
events: {
|
||||
ready(client, payload) {
|
||||
console.log(`Successfully connected Shard ${payload.shardId} to the gateway`);
|
||||
console.log(`Successfully connected Shard ${payload.shardId} to the gateway`)
|
||||
},
|
||||
},
|
||||
intents: ["Guilds", "GuildMessages"],
|
||||
intents: ['Guilds', 'GuildMessages'],
|
||||
token: config.token,
|
||||
});
|
||||
})
|
||||
|
||||
Discord.startBot(client);
|
||||
Discord.startBot(client)
|
||||
```
|
||||
|
||||
Now you can start your bot by running the following command in your terminal:
|
||||
|
||||
@@ -18,14 +18,14 @@ commands show up directly.
|
||||
For this reason, we will now show how to create guild commands, in order to test them immediately.
|
||||
|
||||
```js
|
||||
const guildId = BigInt("YOUR_GUILD_ID");
|
||||
const guildId = BigInt('YOUR_GUILD_ID')
|
||||
const command = {
|
||||
name: "ping",
|
||||
description: "Retrieves the Bot latency",
|
||||
name: 'ping',
|
||||
description: 'Retrieves the Bot latency',
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
client.helpers.createApplicationCommand(command, guildId);
|
||||
client.helpers.createApplicationCommand(command, guildId)
|
||||
```
|
||||
|
||||
This is just very simple example, you can also add sub commands, select options and much more.
|
||||
@@ -36,28 +36,28 @@ Discord sends a WebSocket Event when a user runs a slash command. You can listen
|
||||
`interactionCreate` function in the client.
|
||||
|
||||
```js
|
||||
const Discord = require("discordeno");
|
||||
const config = require("./config.json");
|
||||
const Discord = require('discordeno')
|
||||
const config = require('./config.json')
|
||||
|
||||
const client = Discord.createBot({
|
||||
events: {
|
||||
ready(client, payload) {
|
||||
console.log(`Successfully connected Shard ${payload.shardId} to the gateway`);
|
||||
console.log(`Successfully connected Shard ${payload.shardId} to the gateway`)
|
||||
},
|
||||
async interactionCreate(client, interaction) {
|
||||
if (interaction.data?.name === "ping") {
|
||||
if (interaction.data?.name === 'ping') {
|
||||
return await client.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||
type: Discord.InteractionResponseTypes.ChannelMessageWithSource,
|
||||
data: { content: "🏓 Pong!" },
|
||||
});
|
||||
data: { content: '🏓 Pong!' },
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
intents: Discord.Intents.Guilds | Discord.Intents.GuildMessages,
|
||||
token: config.token,
|
||||
});
|
||||
})
|
||||
|
||||
Discord.startBot(client);
|
||||
Discord.startBot(client)
|
||||
```
|
||||
|
||||
The handling may see complicated in the beginning, but as mentioned before, we will introduce structures to make it
|
||||
|
||||
Reference in New Issue
Block a user