Skip to content

Commit f375bbd

Browse files
committedMar 25, 2023
new file: .gitignore
new file: LICENCE new file: index.js new file: package.json new file: src/config/config.json new file: src/console/watermark.js new file: src/events/client/interactionCreate.js new file: src/events/client/ready.js new file: src/handlers/event.js new file: src/handlers/slash.js new file: src/slashCommands/information/imagine.js
0 parents  commit f375bbd

File tree

12 files changed

+312
-0
lines changed

12 files changed

+312
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
package-lock.json

‎LICENCE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 FlameQuard
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎index.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require('./src/console/watermark')
2+
const { Client, Partials, Collection } = require('discord.js');
3+
const colors = require('colors');
4+
const config = require('./src/config/config.json')
5+
6+
const client = new Client({
7+
intents: [
8+
"Guilds",
9+
"GuildMessages",
10+
"GuildPresences",
11+
"GuildMessageReactions",
12+
"DirectMessages",
13+
"MessageContent",
14+
"GuildVoiceStates"
15+
],
16+
partials: [
17+
Partials.Channel,
18+
Partials.Message,
19+
Partials.User,
20+
Partials.GuildMember,
21+
Partials.Reaction
22+
]
23+
})
24+
25+
if (!config.TOKEN) {
26+
console.log("[WARN] Token for discord bot is required! put your token in config file".yellow.bold + "\n")
27+
return process.exit();
28+
};
29+
30+
client.commands = new Collection()
31+
client.events = new Collection()
32+
client.slash = new Collection()
33+
client.aliases = new Collection()
34+
client.config = require("./src/config/config.json")
35+
36+
module.exports = client;
37+
38+
["event", "slash"].forEach(file => {
39+
require(`./src/handlers/${file}`)(client);
40+
});
41+
42+
client.login(config.TOKEN)
43+
.catch((err) => {
44+
console.log("[CRUSH] Something went wrong while connecting to your bot" + "\n");
45+
console.log("[CRUSH] Error from DiscordAPI :" + err);
46+
process.exit();
47+
})
48+
49+
process.on("unhandledRejection", async (err) => {
50+
console.log(`[ANTI - CRUSH] Unhandled Rejection : ${err}`.red.bold)
51+
})

‎package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"dependencies": {
3+
"colors": "^1.4.0",
4+
"common-tags": "^1.8.2",
5+
"discord.js": "^14.6.0",
6+
"log": "^6.3.1",
7+
"midjourney-client": "github:oelin/midjourney-client"
8+
},
9+
"name": "midjourney-bot",
10+
"version": "1.0.0",
11+
"main": "index.js",
12+
"scripts": {
13+
"start": "node .",
14+
"test": "echo \"Error: no test specified\" && exit 1"
15+
},
16+
"type": "commonjs",
17+
"keywords": [],
18+
"author": "sandarutharuneth",
19+
"license": "ISC",
20+
"description": "opensource discord midjourney bot for everyone without any paywalls"
21+
}

‎src/config/config.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"TOKEN": "YOUR TOKEN",
3+
"CLIENTID": "YOUR BOT ID",
4+
"OWNER": ["YOUR ID"]
5+
}

‎src/console/watermark.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { stripIndent } = require("common-tags");
2+
const colors = require('colors')
3+
4+
console.log(stripIndent`
5+
--------------------------------------------------
6+
█▀█ █▀█ █▀█ ░░█ █▀▀ █▀▀ ▀█▀ █▀█ ▄▀█ ▀█ █▀▀ █▀█
7+
█▀▀ █▀▄ █▄█ █▄█ ██▄ █▄▄ ░█░ █▀▄ █▀█ █▄ ██▄ █▀▄
8+
--------------------------------------------------
9+
`.red.bold)
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { PermissionsBitField, EmbedBuilder } = require('discord.js');
2+
const client = require('../../../index');
3+
4+
module.exports = {
5+
name: "interactionCreate"
6+
};
7+
8+
client.on("interactionCreate", async interaction => {
9+
if (!interaction.isChatInputCommand()) return;
10+
if (!interaction.type == 2) return;
11+
12+
const command = client.slash.get(interaction.commandName);
13+
14+
if (!command) return;
15+
16+
try {
17+
if (command.ownerOnly) {
18+
if (!config.OWNER.includes(interaction.member.id)) {
19+
interaction.reply({
20+
content: `**${interaction.member}** You can't access owner commands`,
21+
ephemeral: true
22+
})
23+
return false;
24+
}
25+
}
26+
27+
if (command.userPermissions) {
28+
if (!interaction.member.permissions.has(PermissionsBitField.resolve(command.userPermissions || []))) return interaction.reply({
29+
content: `${interaction.member} You don't have the required permissions to use this command -> \`${command.userPermissions || []}\``,
30+
ephemeral: true
31+
})
32+
return false;
33+
}
34+
35+
if (command.botPermissions) {
36+
if (!interaction.guild.members.cache.get(client.user.id).permissions.has(PermissionsBitField.resolve(command.botPermissions || []))) return interaction.reply({
37+
content: `${interaction.member} I don't have the required permissions to use this command -> \`${command.botPermissions || []}\``,
38+
ephemeral: true
39+
})
40+
return false;
41+
}
42+
43+
await command.run(client, interaction, interaction.options)
44+
} catch (err) {
45+
console.log(err);
46+
}
47+
})

‎src/events/client/ready.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const client = require('../../../index');
2+
const colors = require('colors');
3+
4+
module.exports = {
5+
name: "ready"
6+
};
7+
8+
client.once('ready', async () => {
9+
console.log("----------------------------------------".white);
10+
console.log(`[READY] ${client.user.tag} is up and ready to go.`.bold)
11+
console.log("----------------------------------------".white);
12+
})

‎src/handlers/event.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fs = require('fs');
2+
const colors = require('colors');
3+
4+
module.exports = (client) => {
5+
console.log("----------------------------------------".yellow);
6+
7+
fs.readdirSync('./src/events/').forEach(dir => {
8+
const commands = fs.readdirSync(`./src/events/${dir}`).filter(file => file.endsWith('.js'));
9+
for (let file of commands) {
10+
let pull = require(`../events/${dir}/${file}`);
11+
if (pull.name) {
12+
client.events.set(pull.name, pull);
13+
console.log(`[HANDLER - EVENTS] Loaded a file : ${pull.name}`.green)
14+
} else {
15+
console.log("\n" + "----------------------------------------".red)
16+
console.log(`[HANDLER - EVENTS] Couldn't load the file ${file}, missing name or aliases`.red.bold)
17+
console.log("----------------------------------------".red)
18+
continue;
19+
}
20+
}
21+
})
22+
console.log("----------------------------------------".yellow);
23+
}

‎src/handlers/slash.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const client = require('../../index');
2+
const config = require("../config/config.json");
3+
const { REST, Routes } = require('discord.js');
4+
const fs = require('fs')
5+
const colors = require('colors');
6+
7+
module.exports = async () => {
8+
console.log("----------------------------------------".yellow);
9+
10+
const slash = [];
11+
12+
fs.readdirSync('./src/slashCommands/').forEach(dir => {
13+
const commands = fs.readdirSync(`./src/slashCommands/${dir}`).filter(file => file.endsWith('.js'));
14+
for (let file of commands) {
15+
let pull = require(`../slashCommands/${dir}/${file}`);
16+
17+
if (pull.name) {
18+
slash.push(pull)
19+
client.slash.set(pull.name, pull);
20+
console.log(`[HANDLER - SLASH] Loaded a file : ${pull.name}`.green);
21+
22+
} else {
23+
console.log(`[HANDLER - SLASH] Couldn't load the file ${file}, missing module name value.`.red)
24+
continue;
25+
}
26+
}
27+
});
28+
29+
if (!config.CLIENTID) {
30+
console.log("[CRUSH] You have to provide your client ID in config file".red + "\n");
31+
return process.exit()
32+
};
33+
34+
const rest = new REST({ version: '10' }).setToken(config.TOKEN);
35+
36+
await rest.put(
37+
Routes.applicationCommands(config.CLIENTID),
38+
{ body: slash }
39+
).then(() => {
40+
console.log("----------------------------------------".magenta);
41+
console.log(`[HANDLER - SLASH] Slash commands has been registered successfully to all the guilds`.magenta.bold);
42+
console.log("----------------------------------------".magenta);
43+
})
44+
}
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const { SlashCommandBuilder, EmbedBuilder, ApplicationCommandOptionType, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
2+
3+
module.exports = {
4+
name: 'imagine',
5+
description: 'Generate art in your dreams!',
6+
options: [
7+
{
8+
name: 'prompt',
9+
type: ApplicationCommandOptionType.String,
10+
description: "Your prompt to generate the art",
11+
required: true,
12+
},
13+
],
14+
run: async (client, interaction) => {
15+
16+
await interaction.deferReply();
17+
18+
const { default: midjourney } = await import('midjourney-client')
19+
const prompt = interaction.options.getString('prompt');
20+
21+
midjourney(prompt).then(response => {
22+
if (response.length < 1) {
23+
interaction.editReply('Unabled to generate images.')
24+
}
25+
26+
const imageURLs = response.join('\n')
27+
28+
const row = new ActionRowBuilder()
29+
.addComponents(
30+
new ButtonBuilder()
31+
.setLabel(`Download`)
32+
.setStyle(ButtonStyle.Link)
33+
.setURL(`${imageURLs}`)
34+
.setEmoji('1083007659457912852'),
35+
new ButtonBuilder()
36+
.setLabel(`Support Us`)
37+
.setStyle(ButtonStyle.Link)
38+
.setURL('https://paypal.me/officialrazer')
39+
.setEmoji('1083016028369453199'))
40+
41+
const embed = new EmbedBuilder()
42+
.setTitle("**Your Prompt:**")
43+
.setDescription(`**${prompt}**`)
44+
.setImage(`${imageURLs}`)
45+
.setColor('#2f3136')
46+
.setFooter({
47+
text: `Requested by: ${interaction.user.username} | ©️ Project Razer `,
48+
iconURL: interaction.user.displayAvatarURL({ dynamic: true }),
49+
})
50+
51+
interaction.editReply({ embeds: [embed], components: [row] });
52+
})
53+
54+
}
55+
}

‎src/slashCommands/information/ping.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { EmbedBuilder } = require('discord.js');
2+
3+
module.exports = {
4+
name: 'ping',
5+
description: '🏓Check my ping!',
6+
run: async (client, interaction) => {
7+
let pembed = new EmbedBuilder()
8+
.setTitle("Pong!")
9+
.setColor('#2F3136')
10+
.setThumbnail('https://i.imgur.com/Cbs7ljR.png')
11+
.addFields({name: '**Latency**', value: `\`\`\`ini\n[ ${Date.now() - interaction.createdTimestamp}ms ]\n\`\`\``, inline: true},
12+
{name: '**API Latency**', value: `\`\`\`ini\n[ ${Math.round(client.ws.ping)}ms ]\n\`\`\``, inline: true})
13+
.setTimestamp()
14+
.setFooter({
15+
text: `©️ Project Razer`,
16+
iconURL: ('https://i.imgur.com/Cbs7ljR.png')
17+
})
18+
interaction.reply({
19+
embeds: [pembed]
20+
});
21+
},
22+
};

0 commit comments

Comments
 (0)
Please sign in to comment.