Creating a component
You can create components simular too commands. A component must be a class extending from the Component
class.
const { Component } = require("gcommands");
module.exports = class extends Component {};
//or
const { Component } = require("gcommands");
class Message extends Component {};
module.exports = Message;
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
We can set the name
(customid name, string or regExp), type
and userRequiredPermissions
.
It is recommended to use the CustomId
class for creating custom id's like this:
const { customId, Button } = require("gcommands");
const customId = new customId({ name: "hello", ids: [author.id] }); // This will create a custom id looking like this: hello-{some_id}
new Button().setCustomId(customId.get())
1
2
3
4
5
2
3
4
5
The array of ids specified above will be extracted from the customId and given to the component run function as args
. You can also use your own customId (string or regex).
const { Component } = require("gcommands");
module.exports = class extends Component {
constructor(client) {
super(client, {
name: "hello",
type: "BUTTON",
userRequiredPermissions: ["MANAGE_MESSAGES"],
})
}
};
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Next we add the run function.
async run(interaction, args) {
return interaction.reply("Hello!");
}
1
2
3
2
3
Resulting code
const { Component } = require("gcommands");
module.exports = class extends Component {
constructor(client) {
super(client, {
name: "hello",
type: "BUTTON",
userRequiredPermissions: ["MANAGE_MESSAGES"],
})
}
async run(interaction, args) {
return interaction.reply("Hello!");
}
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15