質問編集履歴

1

全体コードの追加

2022/08/27 06:48

投稿

sumwave
sumwave

score6

test CHANGED
File without changes
test CHANGED
@@ -49,3 +49,140 @@
49
49
  jsonの内容が変わった際に、fieldsの内容が増えたりするようforでコードを作りたいです。
50
50
  足りない点や意味が分からない場合は指摘してくれると嬉しいです。
51
51
 
52
+ ### 現時点の全体のコード
53
+
54
+ ```bot.js
55
+ const { Client, GatewayIntentBits, Partials } = require('discord.js'),
56
+ client = new Client({
57
+ partials: [Partials.Channel],
58
+ intents: [
59
+ GatewayIntentBits.Guilds,
60
+ GatewayIntentBits.GuildVoiceStates,
61
+ GatewayIntentBits.GuildMessages,
62
+ GatewayIntentBits.GuildMessageReactions,
63
+ GatewayIntentBits.DirectMessages,
64
+ GatewayIntentBits.MessageContent
65
+ ]
66
+ }),
67
+ config = require('./config.json');
68
+ var args, command;
69
+
70
+ client.on("ready", () => {
71
+ console.log("よう");
72
+ client.user.setPresence({
73
+ activities: [{
74
+ name: config.play //プレイ中の内容
75
+ }],
76
+ status: "online"
77
+ });
78
+ });
79
+ client.on('messageCreate', message => {
80
+ if (message.author.bot) return; //bot自身なら実行停止
81
+ if (message.content.startsWith(config.prefix)) { //ボットのプレフィックスからメッセージが始まっているか確認
82
+ args = message.content.slice(config.prefix.length).trim().split(/ +/g);
83
+ command = args.shift().toLowerCase();
84
+ if (command == "help") {
85
+ message.channel.send({
86
+ embeds: [{
87
+ title: "ヘルプ",
88
+ description: "全てのコマンドの初めに`" + config.prefix + "`をつける必要があります。\n今調べられる都道府県の数は、`" + config.data.length + "`個調べられます",
89
+ url: '',
90
+ fields: [
91
+ { name: "沖縄", value: "`okinawa`" },
92
+ { name: "鹿児島", value: "`kagosima`" },
93
+ { name: "宮崎", value: "`miyazaki`" },
94
+ { name: "大分", value: "`ooita`" },
95
+ { name: "熊本", value: "`kumamoto`" },
96
+ { name: "長崎", value: "`nagasaki`" },
97
+ { name: "佐賀", value: "`saga`" },
98
+ { name: "福岡", value: "`fukuoka`" },
99
+ { name: "山口", value: "`yamaguti`" },
100
+ { name: "広島", value: "`hirosima`" },
101
+ { name: "岡山", value: "`okayama`" },
102
+ { name: "島根", value: "`simane`" },
103
+ { name: "鳥取", value: "`tottori`" },
104
+ { name: "ヘルプ", value: "`help`" }
105
+ ],
106
+ }]
107
+ });
108
+ } else {
109
+ message.channel.send("有効なコマンド名ではありません。`" + config.prefix + "help`でコマンドを確認できます。");
110
+ };
111
+ };
112
+ });
113
+ ```
114
+
115
+ ```config.json
116
+ {
117
+ "token": "tokentokentokentokentokent.tokent.tokentokentokentokentokentokentokentok",
118
+ "prefix": "a!",
119
+ "data": [
120
+ {
121
+ "command": "okinawa",
122
+ "name": "沖縄",
123
+ "explanation": ""
124
+ },
125
+ {
126
+ "command": "kagosima",
127
+ "name": "鹿児島",
128
+ "explanation": ""
129
+ },
130
+ {
131
+ "command": "miyazaki",
132
+ "name": "宮崎",
133
+ "explanation": ""
134
+ },
135
+ {
136
+ "command": "ooita",
137
+ "name": "大分",
138
+ "explanation": ""
139
+ },
140
+ {
141
+ "command": "kumamoto",
142
+ "name": "熊本",
143
+ "explanation": ""
144
+ },
145
+ {
146
+ "command": "nagasaki",
147
+ "name": "長崎",
148
+ "explanation": ""
149
+ },
150
+ {
151
+ "command": "saga",
152
+ "name": "佐賀",
153
+ "explanation": ""
154
+ },
155
+ {
156
+ "command": "fukuoka",
157
+ "name": "福岡",
158
+ "explanation": ""
159
+ },
160
+ {
161
+ "command": "yamaguti",
162
+ "name": "山口",
163
+ "explanation": ""
164
+ },
165
+ {
166
+ "command": "hirosima",
167
+ "name": "広島",
168
+ "explanation": ""
169
+ },
170
+ {
171
+ "command": "okayama",
172
+ "name": "岡山",
173
+ "explanation": ""
174
+ },
175
+ {
176
+ "command": "simane",
177
+ "name": "島根",
178
+ "explanation": ""
179
+ },
180
+ {
181
+ "command": "tottori",
182
+ "name": "鳥取",
183
+ "explanation": ""
184
+ }
185
+ ]
186
+ }
187
+
188
+ ```