-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
62 lines (50 loc) · 1.85 KB
/
main.ts
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
import { createBot, getBotIdFromToken, startBot, Intents, CreateSlashApplicationCommand, Bot, Interaction, InteractionResponseTypes } from "@discordeno/mod.ts";
import "$std/dotenv/load.ts"
interface SlashCommand {
info: CreateSlashApplicationCommand;
response(bot: Bot, interaction: Interaction): Promise<void>;
};
// Botのトークンを.envから取得
const BotToken: string = Deno.env.get("BOT_TOKEN")!;
const HelloCommand: SlashCommand = {
// コマンド情報
info: {
name: "hello_world",
description: "こんにちはと返します。"
},
// コマンド内容
response: async (bot, interaction) => {
return await bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource,
data: {
content: "こんにちは",
// エフェメラルメッセージ (https://discord.com/developers/docs/resources/message#message-object-message-flags)
flags: 1 << 6
}
});
}
}
// ボットの作成
const bot = createBot({
token: BotToken,
botId: getBotIdFromToken(BotToken) as bigint,
intents: Intents.Guilds | Intents.GuildMessages,
// イベント発火時に実行する関数など
events: {
// 起動時
ready: (_bot, payload) => {
console.log(`${payload.user.username} is ready!`);
},
interactionCreate:async (_bot, interaction) => {
await HelloCommand.response(bot, interaction);
}
}
});
// コマンドの作成
bot.helpers.createGlobalApplicationCommand(HelloCommand.info);
// コマンドの登録
bot.helpers.upsertGlobalApplicationCommands([HelloCommand.info]);
await startBot(bot);
Deno.cron("Continuous Request", "*/2 * * * *", () => {
console.log("running...");
});