forked from AuroraBot-Discord/Bot-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (71 loc) · 2.65 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const { Client, Intents, Interaction, Message } = require("discord.js");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], restTimeOffset: 0 });
const prefix = "!";
client.once("ready", () => {
console.log(`Logged in as ${client.user.tag}.`);
});
/**
*
* @param {Interaction} interaction
*/
client.on("interactionCreate", async (interaction) => {
if (interaction.isCommand()) {
const { commandName:command, options } = interaction;
if (command === "eval") {
if (!["eval実行可能なユーザーID"].includes(interaction.user.id)) return interaction.reply({ content: "あなたはこのコマンドを実行できません。", ephemeral: true });
await interaction.deferReply();
const code = options.getString("code");
const result = new Promise((resolve) => resolve(eval(code)));
return result
.then(async (output) => {
if (typeof output !== "string") {
output = require("util").inspect(output, { depth: 0 });
}
if (output.includes(client.token)) {
output = output.replace(client.token, "[TOKEN]");
}
interaction.followUp(`\`\`\`js\n${output}\n\`\`\``);
})
.catch(async (err) => {
err = err.toString();
if (err.includes(client.token)) {
err = err.replace(client.token, "[TOKEN]");
}
interaction.followUp(`\`\`\`js\n${err}\n\`\`\``);
});
}
}
});
/**
*
* @param {Message} message
*/
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "eval") {
if (!["eval実行可能なユーザーID"].includes(message.author.id)) return message.reply({ content: "あなたはこのコマンドを実行できません。" });
const code = args.join(" ");
const result = new Promise((resolve) => resolve(eval(code)));
return result
.then(async (output) => {
if (typeof output !== "string") {
output = require("util").inspect(output, { depth: 0 });
}
if (output.includes(client.token)) {
output = output.replace(client.token, "[TOKEN]");
}
message.reply(`\`\`\`js\n${output}\n\`\`\``);
})
.catch(async (err) => {
err = err.toString();
if (err.includes(client.token)) {
err = err.replace(client.token, "[TOKEN]");
}
message.reply(`\`\`\`js\n${err}\n\`\`\``);
});
}
});
client.login(process.env.BOT_TOKEN);