generator-discord 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -3
- package/src/index.ts +5 -0
- package/templates/javascript/config.json +3 -0
- package/templates/javascript/package.json +0 -1
- package/templates/javascript/src/index.js +9 -15
- package/templates/python/bot.py +21 -0
- package/templates/typescript/config.json +3 -0
- package/templates/typescript/package.json +0 -1
- package/templates/typescript/src/index.ts +9 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generator-discord",
|
|
3
3
|
"displayName": "Generator-Discord",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"main": "./app/index.js",
|
|
6
6
|
"description": "Yeoman generator for Discord.js",
|
|
7
7
|
"keywords": [
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "tsc",
|
|
15
15
|
"watch": "tsc -w",
|
|
16
|
+
"test": "vitest run",
|
|
16
17
|
"debug": "npm i -g generator-discord && npx --node-arg=--inspect yo discord"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
@@ -32,10 +33,13 @@
|
|
|
32
33
|
},
|
|
33
34
|
"homepage": "https://github.com/emilkrebs/Generator-Discord",
|
|
34
35
|
"dependencies": {
|
|
36
|
+
"@types/yeoman-test": "~4.0.3",
|
|
35
37
|
"typescript": "^4.7.2",
|
|
36
|
-
"yeoman-generator": "^5.6.1"
|
|
38
|
+
"yeoman-generator": "^5.6.1",
|
|
39
|
+
"yeoman-test": "~7.3.0"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
|
-
"@types/yeoman-generator": "^5.2.10"
|
|
42
|
+
"@types/yeoman-generator": "^5.2.10",
|
|
43
|
+
"vitest": "^0.29.2"
|
|
40
44
|
}
|
|
41
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
const { Client, Intents } = require('discord.js');
|
|
2
|
-
const colors = require('colors');
|
|
3
2
|
const { token } = require('../config.json');
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
// Create a new client instance with Intents that specify which privileged intents your bot requires
|
|
6
5
|
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
// Run this code when the client is ready. This event will only trigger one time after logging in
|
|
9
9
|
client.once('ready', () => {
|
|
10
|
-
console.log(
|
|
11
|
-
console.log(getTime() + colors.green(`Bot is logged in as ${colors.yellow(client.user.tag)}.`));
|
|
10
|
+
console.log(`Bot is logged in as ${client.user.tag}.`);
|
|
12
11
|
});
|
|
13
12
|
|
|
14
|
-
//
|
|
13
|
+
// Listen for messages
|
|
15
14
|
client.on('messageCreate', async message => {
|
|
16
15
|
const { content } = message;
|
|
16
|
+
// Reply with "Pong!" when someone says "!ping"
|
|
17
17
|
if (content === "!ping") {
|
|
18
|
-
return await message.reply("
|
|
18
|
+
return await message.reply("Pong!");
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
//
|
|
24
|
-
function getTime() {
|
|
25
|
-
let dateTime = new Date()
|
|
26
|
-
return colors.gray(`[${dateTime.getHours()}:${dateTime.getMinutes()}:${dateTime.getSeconds()}] `);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// login with your client's token
|
|
23
|
+
// Login to Discord with your app's token
|
|
30
24
|
client.login(token);
|
|
31
25
|
|
|
32
|
-
//
|
|
26
|
+
// For more information about the Discord.js library, visit https://discord.js.org/#/docs/main/stable/general/welcome
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import discord
|
|
2
|
+
from discord.ext import commands
|
|
3
|
+
|
|
4
|
+
# Define bot prefix and create bot instance
|
|
5
|
+
bot_prefix = "!"
|
|
6
|
+
bot = commands.Bot(command_prefix=bot_prefix)
|
|
7
|
+
|
|
8
|
+
# Define bot events
|
|
9
|
+
@bot.event
|
|
10
|
+
async def on_ready():
|
|
11
|
+
print(f"Logged in as {bot.user.name} ({bot.user.id})")
|
|
12
|
+
|
|
13
|
+
# Define bot commands
|
|
14
|
+
@bot.command()
|
|
15
|
+
async def ping(ctx):
|
|
16
|
+
await ctx.send("Pong!")
|
|
17
|
+
|
|
18
|
+
# Run bot with bot token
|
|
19
|
+
bot.run("<%= bot-token %>")
|
|
20
|
+
|
|
21
|
+
# For more information on how to use discord.py, visit https://discordpy.readthedocs.io/en/latest/
|
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
import { Client, Intents } from 'discord.js';
|
|
2
|
-
import colors from 'colors';
|
|
3
2
|
import { token } from '../config.json';
|
|
4
3
|
|
|
4
|
+
// Create a new client instance with Intents that specify which privileged intents your bot requires
|
|
5
5
|
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
|
|
6
6
|
|
|
7
|
-
//
|
|
7
|
+
// Run this code when the client is ready. This event will only trigger one time after logging in
|
|
8
8
|
client.once('ready', () => {
|
|
9
|
-
console.log(
|
|
10
|
-
console.log(getTime() + colors.green(`Bot is logged in as ${colors.yellow(client.user!.tag)}.`));
|
|
9
|
+
console.log(`Bot is logged in as ${client.user.tag}.`);
|
|
11
10
|
});
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
// Listen for messages
|
|
14
14
|
client.on('messageCreate', async message => {
|
|
15
15
|
const { content } = message;
|
|
16
|
+
// Reply with "Pong!" when someone says "!ping"
|
|
16
17
|
if (content === "!ping") {
|
|
17
|
-
await message.reply("
|
|
18
|
+
await message.reply("Pong!");
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
// get the current time to get useful log messages
|
|
23
|
-
function getTime() {
|
|
24
|
-
let dateTime = new Date()
|
|
25
|
-
return colors.gray(`[${dateTime.getHours()}:${dateTime.getMinutes()}:${dateTime.getSeconds()}] `);
|
|
26
|
-
}
|
|
27
23
|
|
|
28
|
-
//
|
|
24
|
+
// Login to Discord with your app's token
|
|
29
25
|
client.login(token);
|
|
30
26
|
|
|
31
|
-
//
|
|
27
|
+
// For more information about the Discord.js library, visit https://discord.js.org/#/docs/main/stable/general/welcome
|