Skip to content

Commit f589443

Browse files
committed
First Commit
1 parent 96a9989 commit f589443

File tree

10 files changed

+216
-1
lines changed

10 files changed

+216
-1
lines changed

.replit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run="npx node index.js"

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# d.js-bot
1+
# d.js-bot
2+
これは自分用です。
3+
ClientやMessageに直接生えさせているのがいやだという方はしようしないでください。

client.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { MessageEmbed, Collection } = require("discord.js");
2+
3+
const config = {
4+
prefix: "dev!",
5+
embed: {
6+
colors: {
7+
Default: "#00FF7F",
8+
Youtube: "#FF0000"
9+
},
10+
footer: { text: "Created by !¿֍𝓪𝓷𝓶𝓸𝓽𝓲֍?¡#0163" },
11+
},
12+
blacklist: {
13+
user: []
14+
},
15+
auth: {
16+
discord: "TOKEN"
17+
}
18+
};
19+
20+
const cache = {
21+
startDate: Date.now
22+
};
23+
24+
const func = {
25+
reply: (data, message) => {
26+
let res;
27+
if (data !== null && typeof data === "object") {
28+
res = data;
29+
res.allowedMentions?.repliedUser ?? false;
30+
} else {
31+
res = {
32+
content: data,
33+
allowedMentions: { repliedUser: false }
34+
};
35+
};
36+
return message.reply(res);
37+
},
38+
embed: (color = config.embed.colors.Default) => {
39+
const embed = new MessageEmbed()
40+
.setFooter(config.embed.footer)
41+
.setColor(color)
42+
.setTimestamp();
43+
return embed;
44+
}
45+
};
46+
47+
module.exports = {
48+
config: config,
49+
cache: cache,
50+
func: func
51+
};

commands/Other/help.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
name: "help",
3+
description: "ボットコマンド一覧",
4+
usages: ["", "<コマンドの名前>"],
5+
aliases: ["command", "commands"],
6+
cooldown: 0,
7+
guild: false,
8+
message(message) {
9+
const embed = message.client.func.embed();
10+
if (!message.args[0]) {
11+
embed.setTitle("botのコマンド一覧");
12+
const categories = Array.from(new Set(message.client.commands.map(command => command.category))).sort();
13+
categories.forEach(category => {
14+
const data = message.client.commands.map(command => command.category == category ? `\`${message.prefix}${command.name}\` -- ${command.description}\n` : "");
15+
embed.addField(category, data.join(""));
16+
});
17+
} else {
18+
const command = message.client.commands.search(message.args[0]);
19+
if (!command) return message.channel.error(`**${message.args[0]}**のコマンドが存在しません。`);
20+
const pcmd = message.prefix + command.name + " ";
21+
embed.setTitle(`${command.name}の詳細`)
22+
.addField("説明", command.description)
23+
.addField("使用方法", command.usages.length > 1 ? command.usages.map(usage => pcmd + usage).join("\n") : pcmd);
24+
if (command.aliases.length > 1) embed.addField("短縮コマンド", command.aliases.map(alias => message.prefix + alias).join("\n"), true);
25+
embed.addField("クールダウン", `**${command.cooldown ? `${command.cooldown}秒` : "なし"}**`, true);
26+
};
27+
message.channel.send({ embeds: [embed] });
28+
}
29+
};

commands/Other/ping.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
name: "ping",
3+
description: "botのpingを計測します",
4+
usages: [],
5+
aliases: [],
6+
cooldown: 1,
7+
guild: false,
8+
async message(message) {
9+
const ping_msg = await message.channel.send("Pong!\npingを計測しています。");
10+
ping_msg.edit(`Pong!\nWebSocket: **${ping_msg.createdTimestamp - message.createdTimestamp}ms** | Latency: **${message.client.ws.ping}**ms`);
11+
}
12+
};

events/messageCreate.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const time_fmt = require("../util/time-format");
2+
3+
module.exports = async (message) => {
4+
if (message.author.bot || message.channel.type === "dm") return;
5+
if (!message.channel.permissionsFor(message.guild.me).has("SEND_MESSAGES")) return;
6+
7+
/*---------------FUNCTION---------------*/
8+
message.no_reply = data => { message.client.func.no_reply(data, message) };
9+
10+
message.error = (data = null) => {
11+
if (message.command.cooldown) {
12+
clearInterval(message.command.cooldowns.interval);
13+
message.command.cooldowns.delete();
14+
};
15+
if (data !== null) message.no_reply(data);
16+
};
17+
18+
/*---------------COMMAND---------------*/
19+
message.prefix = message.client.config.prefix;
20+
if (!message.content.startsWith(message.prefix)) return;
21+
message.args = message.content.slice(message.prefix.length).split(/ +/);
22+
message.command = message.client.commands.search(message.args.shift().toLowerCase());
23+
if (!message.command) return;
24+
if (message.command.guild && !message.inGuild()) return message.no_reply("このコマンドはサーバー内で実行して下さい。");
25+
26+
/*---------------COOLDDOWN---------------*/
27+
if (message.command.cooldown) {
28+
if (message.command.cooldowns.has(message.author.id)) {
29+
const time_raw = Date.now() - message.command.cooldowns.get(message.author.id);
30+
const time = time_fmt(message.command.cooldown - Math.round(time_raw / 1000));
31+
return message.error(`\`${message.command.name}\`は後**${time}**実行できません。`)
32+
} else {
33+
message.command.cooldowns.set(message.author.id, Date.now());
34+
message.command.cooldowns.interval = setTimeout(() => {
35+
message.command.cooldowns.delete(message.author.id);
36+
}, message.command.cooldown * 1000);
37+
};
38+
};
39+
40+
/*---------------BLACKLIST---------------*/
41+
const blacklist = message.client.config.blacklist;
42+
if (blacklist.user.includes(message.author.id)) return message.error("あなたはブラックリストに登録されています。");
43+
44+
/*---------------RUNCOMMAND---------------*/
45+
console.log(message)
46+
try {
47+
message.command.message(message)
48+
} catch (error) {
49+
console.log("エラーが発生しました。");
50+
console.log(error);
51+
try {
52+
message.no_reply(`エラーが発生しました。発生したエラーは以下の通りです。\`\`\`${error}\`\`\`いかのサーバーで報告してください。\rhttps://discord.gg/sJ58GV4WxG`);
53+
} catch { return };
54+
};
55+
};

events/ready.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const http = require("http");
2+
3+
module.exports = client => {
4+
console.log(`[Login]: ${client.user.tag}`);
5+
console.log(`[Login]: Time >> ${Date.now - client.cache.startDate}ms`);
6+
client.user.setPresence({
7+
activity: {
8+
name: `${client.config.prefix}help`, type: 'WATCHING'
9+
},
10+
status: 'online'
11+
});
12+
};

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { Client, Intents } = require("discord.js");
2+
const loader = require("./util/loader");
3+
4+
const client = new Client({ intents: Object.keys(Intents.FLAGS) });
5+
Object.entries(require("./client"))
6+
.forEach(data => client[data[0]] = data[1]);
7+
loader.commands(client);
8+
loader.events(client);
9+
10+
client.login(client.config.auth.discord);

util/loader.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fs = require("fs");
2+
const { Collection } = require("discord.js");
3+
4+
module.exports = {
5+
commands(client) {
6+
const dir = "./commands";
7+
client.commands = new Collection();
8+
client.commands.search = name => { return client.commands.get(name) || client.commands.find(command => command.aliases && command.aliases.includes(name)) };
9+
fs.readdirSync(dir)
10+
.forEach(folder => {
11+
const folderPath = `${dir}/${folder}/`;
12+
fs.readdirSync(folderPath)
13+
.forEach(file => {
14+
if (!file.endsWith(".js")) return;
15+
const command = require("../" + folderPath + file);
16+
command.category = folder;
17+
if (command.cooldown) command.cooldowns = new Collection();
18+
client.commands.set(command.name, command);
19+
console.log(`[Command loaded]: ${folder} > ${command.name}`);
20+
});
21+
});
22+
},
23+
events(client) {
24+
const dir = "./events";
25+
fs.readdirSync(dir)
26+
.forEach(file => {
27+
if (!file.endsWith(".js")) return;
28+
const eventName = file.split(".")[0];
29+
client.on(eventName, require(`../${dir}/${file}`));
30+
console.log(`[Event loaded]: ${eventName}`);
31+
});
32+
}
33+
};

util/time-format.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = time => {
2+
const hour = time / 3600 | 0;
3+
const minute = time % 3600 / 60 | 0;
4+
const second = time % 60;
5+
let data = "";
6+
if (hour != 0) data += hour + "時間";
7+
if (minute != 0) data += minute + "分";
8+
if (second != 0) data += second + "秒";
9+
return data;
10+
};

0 commit comments

Comments
 (0)