-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const {Command, CommandType, MessageActionRow, MessageButton, CustomId} = require('../../dist'); | ||
|
||
new Command({ | ||
name: 'hello', | ||
description: 'Says hello!', | ||
type: [CommandType.SLASH, CommandType.MESSAGE], | ||
run: (ctx) => { | ||
const row = new MessageActionRow().addComponents([ | ||
new MessageButton() | ||
.setCustomId(CustomId('hello', ctx.userId)) | ||
.setLabel('Click me!') | ||
.setStyle('SUCCESS') | ||
]); | ||
|
||
return ctx.reply({content: `Hello ${ctx.username}!`, components: [row]}); | ||
} | ||
}); | ||
|
||
new class extends Command { | ||
constructor() { | ||
super({ | ||
name: 'hello', | ||
description: 'Says hello!', | ||
type: [CommandType.SLASH, CommandType.MESSAGE], | ||
}); | ||
} | ||
|
||
run(ctx) { | ||
const row = new MessageActionRow().addComponents([ | ||
new MessageButton() | ||
.setCustomId(CustomId('hello', ctx.userId)) | ||
.setLabel('Click me!') | ||
.setStyle('SUCCESS') | ||
]); | ||
|
||
return ctx.reply({content: `Hello ${ctx.username}!`, components: [row]}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const {Argument, ArgumentType, Command, CommandType, CustomId, MessageActionRow, MessageButton} = require('../../dist'); | ||
const { MongoDBProvider } = require('../../dist/providers/MongoDBProvider'); | ||
|
||
// You can still use classes, but you will need to put the "new" keyword front of it | ||
new Command({ | ||
name: 'introduce', | ||
description: 'Introduce yourself', | ||
type: [CommandType.SLASH, CommandType.CONTEXT_USER, CommandType.MESSAGE], | ||
arguments: [ | ||
new Argument('name', { | ||
description: 'Your name', | ||
type: ArgumentType.STRING, | ||
required: true, | ||
}) | ||
], | ||
run: (ctx) => { | ||
const name = ctx.arguments.getUser('user')?.username || ctx.arguments.getString('name'); | ||
|
||
const row = new MessageActionRow().addComponents([ | ||
new MessageButton() | ||
.setCustomId(CustomId('introduce', name, ctx.userId)) | ||
.setLabel('Click me!') | ||
.setStyle('SUCCESS'), | ||
]); | ||
|
||
return ctx.reply({content: `Hello ${name}! I am ${ctx.client.user.username}.`, components: [row]}); | ||
}, | ||
// Called when an error occurs during the execution of run() | ||
onError: (ctx) => { | ||
return ctx.reply('I dont think I want to introduce myself to you.'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const {Component, ComponentType} = require('../../dist'); | ||
|
||
new Component({ | ||
name: 'hello', | ||
type: [ComponentType.BUTTON], | ||
run: (ctx) => { | ||
return ctx.reply(`Hello again ${ctx.username}!`); | ||
} | ||
}); | ||
|
||
new class extends Component { | ||
constructor() { | ||
super({ | ||
name: 'hello', | ||
type: [ComponentType.BUTTON], | ||
}); | ||
} | ||
|
||
run(ctx) { | ||
return ctx.reply(`Hello again ${ctx.username}!`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const {Component, ComponentType} = require('../../dist'); | ||
|
||
// You can still use classes, but you will need to put the "new" keyword front of it | ||
new Component({ | ||
name: 'introduce', | ||
type: [ComponentType.BUTTON], | ||
run: (ctx) => { | ||
ctx.reply(`Hello again ${ctx.arguments[0]}!`); | ||
}, | ||
onError: (ctx) => { | ||
ctx.reply(`I dont want to say hello to you ${ctx.arguments[0]}`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// const {GClient} = require('gcommands')! | ||
require('dotenv').config(); | ||
const {GClient, Plugins, Logger} = require('../dist'); | ||
const {Intents} = require('discord.js'); | ||
const path = require('path'); | ||
|
||
// Search for plugins in node_modules (folder names starting with gcommands-plugin- or @gcommands/plugin-) or plugins folder | ||
Plugins.search(__dirname); | ||
|
||
// Set the log level | ||
Logger.setLevel(Logger.TRACE); | ||
|
||
const client = new GClient({ | ||
dirs: [ | ||
path.join(__dirname, 'commands'), | ||
path.join(__dirname, 'components'), | ||
path.join(__dirname, 'listeners') | ||
], | ||
messagePrefix: '!', | ||
devGuildId: process.env.DEV_SERVER, | ||
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], | ||
}); | ||
|
||
// See commands/introduce.js (new syntax) | ||
// See commands/class.js (old class syntax) | ||
// See components/introduce.js (new syntax) | ||
// See listeners/ready.js (new syntax) | ||
|
||
client.on('error', console.log); | ||
client.on('warn', console.log); | ||
|
||
client.login(process.env.token); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const {Listener} = require('../../dist'); | ||
|
||
new Listener({ | ||
name: 'ready', | ||
event: 'ready', | ||
once: true, | ||
run: (client) => { | ||
return console.log(`Ready! Initialized with ${client.guilds.cache.size} guilds`); | ||
} | ||
}); |