-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscord-Bot-Control-GUI.ps1
548 lines (485 loc) · 25.2 KB
/
Discord-Bot-Control-GUI.ps1
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<# ========================== Discord Bot Control GUI ==========================
SYNOPSIS
This script generates a GUI window to control a Discord Bot in Powershell.
FEATURES
- Display all guilds
- Display Channels in a Guild
- Display Messages for each Channel
- Send a Message as the Bot
- Create an Invite Link for selected Channel
- Create a channel with custom name
- Delete a selected channel
- Kick / Ban Selected Users
- Unban username
USAGE
1. Run the script to open the GUI window.
2. Input your token.
3. Control the bot actions in 'Control' Tab.
#>
$HideConsole = 1 # HIDE THE WINDOW - Change to 1 to hide the console window while running
# Load Windows Forms assembly
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$imageUrl = "https://i.imgur.com/v162hMS.png"
$client = New-Object System.Net.WebClient
$imageBytes = $client.DownloadData($imageUrl)
$ms = New-Object IO.MemoryStream($imageBytes, 0, $imageBytes.Length)
# Create the main form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Discord LiveBot"
$form.Size = New-Object System.Drawing.Size(1400, 920)
$form.Font = 'Microsoft Sans Serif,10'
$form.BackColor = "#242424"
$form.ForeColor = [System.Drawing.Color]::White
# Create a tab control to switch between login and main application
$tabControl = New-Object System.Windows.Forms.TabControl
$tabControl.Dock = 'Fill'
$tabControl.Font = 'Microsoft Sans Serif,11'
$tabControl.BackColor = "#242424"
# Create the login tab
$loginTab = New-Object System.Windows.Forms.TabPage
$loginTab.Text = "Login"
$loginTab.BackgroundImage = [System.Drawing.Image]::FromStream($ms, $true)
$loginTab.BackgroundImageLayout = [System.Windows.Forms.ImageLayout]::zoom
$loginTab.BackColor = "#242424"
# Token Label
$tokenLabel = New-Object System.Windows.Forms.Label
$tokenLabel.Text = "Discord Bot Token"
$tokenLabel.Location = New-Object System.Drawing.Point(600, 300)
$tokenLabel.Size = New-Object System.Drawing.Size(200, 33)
$tokenLabel.Font = 'Microsoft Sans Serif,16,style=Bold'
# Token TextBox
$tokenTextBox = New-Object System.Windows.Forms.TextBox
$tokenTextBox.Location = New-Object System.Drawing.Point(400, 340)
$tokenTextBox.Width = 600
$tokenTextBox.Height = 40
$tokenTextBox.Font = 'Microsoft Sans Serif,10'
$tokenTextBox.BackColor = "#242424"
$tokenTextBox.ForeColor = [System.Drawing.Color]::White
# Login Button
$loginButton = New-Object System.Windows.Forms.Button
$loginButton.Text = "Login"
$loginButton.Location = New-Object System.Drawing.Point(640, 380)
$loginButton.Size = New-Object System.Drawing.Size(100, 40)
$loginButton.Width = 100
$loginButton.BackColor = "#242424"
$loginButton.ForeColor = [System.Drawing.Color]::White
$loginButton.Font = 'Microsoft Sans Serif,12,style=Bold'
# Add controls to the login tab
$loginTab.Controls.AddRange(@($tokenLabel, $tokenTextBox, $loginButton))
$tabControl.TabPages.Add($loginTab)
# Create the main application tab
$appTab = New-Object System.Windows.Forms.TabPage
$appTab.Text = "Control "
$appTab.BackgroundImage = [System.Drawing.Image]::FromStream($ms, $true)
$appTab.BackgroundImageLayout = [System.Windows.Forms.ImageLayout]::zoom
$appTab.BackColor = "#242424"
# Layout: Labels and ListBoxes
$guildsLabel = New-Object System.Windows.Forms.Label
$guildsLabel.Text = "Guilds"
$guildsLabel.Location = New-Object System.Drawing.Point(10, 10)
$guildsLabel.Font = 'Microsoft Sans Serif,12,style=Bold'
$guildsListBox = New-Object System.Windows.Forms.ListBox
$guildsListBox.Location = New-Object System.Drawing.Point(10, 40)
$guildsListBox.Size = New-Object System.Drawing.Size(250, 600)
$guildsListBox.BackColor = "#242424"
$guildsListBox.ForeColor = [System.Drawing.Color]::White
$channelsLabel = New-Object System.Windows.Forms.Label
$channelsLabel.Text = "Channels"
$channelsLabel.Location = New-Object System.Drawing.Point(270, 10)
$channelsLabel.Font = 'Microsoft Sans Serif,12,style=Bold'
$channelsListBox = New-Object System.Windows.Forms.ListBox
$channelsListBox.Location = New-Object System.Drawing.Point(270, 40)
$channelsListBox.Size = New-Object System.Drawing.Size(250, 600)
$channelsListBox.BackColor = "#242424"
$channelsListBox.ForeColor = [System.Drawing.Color]::White
$usersLabel = New-Object System.Windows.Forms.Label
$usersLabel.Text = "Members"
$usersLabel.Location = New-Object System.Drawing.Point(1110, 10)
$usersLabel.Font = 'Microsoft Sans Serif,12,style=Bold'
$usersListBox = New-Object System.Windows.Forms.ListBox
$usersListBox.Location = New-Object System.Drawing.Point(1110, 40)
$usersListBox.Size = New-Object System.Drawing.Size(250, 800)
$usersListBox.BackColor = "#242424"
$usersListBox.ForeColor = [System.Drawing.Color]::White
$messagesLabel = New-Object System.Windows.Forms.Label
$messagesLabel.Text = "Messages"
$messagesLabel.Location = New-Object System.Drawing.Point(530, 10)
$messagesLabel.Font = 'Microsoft Sans Serif,12,style=Bold'
$outputBox = New-Object System.Windows.Forms.RichTextBox
$outputBox.Location = New-Object System.Drawing.Point(530, 40)
$outputBox.Size = New-Object System.Drawing.Size(565, 750)
$outputBox.ReadOnly = $true
$outputBox.BackColor = "#242424"
$outputBox.ForeColor = [System.Drawing.Color]::White
$outputBox.Font = 'Microsoft Sans Serif,11'
$messageTextBox = New-Object System.Windows.Forms.TextBox
$messageTextBox.Location = New-Object System.Drawing.Point(530, 800)
$messageTextBox.Size = New-Object System.Drawing.Size(450, 30)
$messageTextBox.BackColor = "#242424"
$messageTextBox.ForeColor = [System.Drawing.Color]::White
$sendButton = New-Object System.Windows.Forms.Button
$sendButton.Text = "Send"
$sendButton.Location = New-Object System.Drawing.Point(1000, 796)
$sendButton.Size = New-Object System.Drawing.Size(90, 30)
$sendButton.BackColor = "#242424"
$sendButton.ForeColor = [System.Drawing.Color]::White
$sendButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Generate Invite Link Button
$generateInviteButton = New-Object System.Windows.Forms.Button
$generateInviteButton.Text = "Generate Invite Link"
$generateInviteButton.Location = New-Object System.Drawing.Point(15, 647)
$generateInviteButton.Size = New-Object System.Drawing.Size(160, 30)
$generateInviteButton.BackColor = "#242424"
$generateInviteButton.ForeColor = [System.Drawing.Color]::White
$generateInviteButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Output box for invite link
$inviteLinkBox = New-Object System.Windows.Forms.TextBox
$inviteLinkBox.Location = New-Object System.Drawing.Point(190, 650)
$inviteLinkBox.Size = New-Object System.Drawing.Size(320, 30)
$inviteLinkBox.Text = "No Link Generated"
$inviteLinkBox.ReadOnly = $true
$inviteLinkBox.BackColor = "#242424"
$inviteLinkBox.ForeColor = [System.Drawing.Color]::White
$inviteLinkBox.Font = 'Microsoft Sans Serif,10'
$newChannelNameTextBox = New-Object System.Windows.Forms.TextBox
$newChannelNameTextBox.Location = New-Object System.Drawing.Point(20, 690)
$newChannelNameTextBox.Size = New-Object System.Drawing.Size(150, 30)
$newChannelNameTextBox.Text = "new-channel-name"
$newChannelNameTextBox.BackColor = "#242424"
$newChannelNameTextBox.ForeColor = [System.Drawing.Color]::White
$newChannelNameTextBox.Font = 'Microsoft Sans Serif,10'
# Button to create a new channel
$createChannelButton = New-Object System.Windows.Forms.Button
$createChannelButton.Text = "Create Channel"
$createChannelButton.Location = New-Object System.Drawing.Point(185, 687)
$createChannelButton.Size = New-Object System.Drawing.Size(130, 30)
$createChannelButton.BackColor = "#242424"
$createChannelButton.ForeColor = [System.Drawing.Color]::White
$createChannelButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Button to delete selected channel
$deleteChannelButton = New-Object System.Windows.Forms.Button
$deleteChannelButton.Text = "Delete Selected Channel"
$deleteChannelButton.Location = New-Object System.Drawing.Point(325, 687)
$deleteChannelButton.Size = New-Object System.Drawing.Size(190, 30)
$deleteChannelButton.BackColor = "#242424"
$deleteChannelButton.ForeColor = [System.Drawing.Color]::White
$deleteChannelButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Kick Button
$kickButton = New-Object System.Windows.Forms.Button
$kickButton.Text = "Kick Selected Member"
$kickButton.Location = New-Object System.Drawing.Point(15, 730)
$kickButton.Size = New-Object System.Drawing.Size(240, 30)
$kickButton.BackColor = "#242424"
$kickButton.ForeColor = [System.Drawing.Color]::White
$kickButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Ban Button
$banButton = New-Object System.Windows.Forms.Button
$banButton.Text = "Ban Selected Member"
$banButton.Location = New-Object System.Drawing.Point(270, 730)
$banButton.Size = New-Object System.Drawing.Size(240, 30)
$banButton.BackColor = "#242424"
$banButton.ForeColor = [System.Drawing.Color]::White
$banButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Unban Input Box for username
$unbanUserTextBox = New-Object System.Windows.Forms.TextBox
$unbanUserTextBox.Location = New-Object System.Drawing.Point(20, 775)
$unbanUserTextBox.Size = New-Object System.Drawing.Size(150, 30)
$unbanUserTextBox.Text = "username"
$unbanUserTextBox.BackColor = "#242424"
$unbanUserTextBox.ForeColor = [System.Drawing.Color]::White
# Unban Button
$unbanButton = New-Object System.Windows.Forms.Button
$unbanButton.Text = "Unban Username"
$unbanButton.Location = New-Object System.Drawing.Point(180, 772)
$unbanButton.Size = New-Object System.Drawing.Size(160, 30)
$unbanButton.BackColor = "#242424"
$unbanButton.ForeColor = [System.Drawing.Color]::White
$unbanButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Invite User Button
$inviteuserButton = New-Object System.Windows.Forms.Button
$inviteuserButton.Text = "Invite Username"
$inviteuserButton.Location = New-Object System.Drawing.Point(350, 772)
$inviteuserButton.Size = New-Object System.Drawing.Size(160, 30)
$inviteuserButton.BackColor = "#242424"
$inviteuserButton.ForeColor = [System.Drawing.Color]::White
$inviteuserButton.Font = 'Microsoft Sans Serif,10,style=Bold'
# Add controls to the app tab
$appTab.Controls.AddRange(@($messagesLabel, $guildsLabel, $guildsListBox, $channelsLabel, $channelsListBox, $usersLabel, $usersListBox, $outputBox, $messageTextBox, $sendButton, $generateInviteButton, $inviteLinkBox, $newChannelNameLabel, $newChannelNameTextBox, $createChannelButton, $deleteChannelButton, $unbanUserTextBox, $unbanButton, $kickButton, $banButton, $inviteuserButton))
$tabControl.TabPages.Add($appTab)
$form.Controls.Add($tabControl)
# Login button click event
$loginButton.Add_Click({
$token = $tokenTextBox.Text
if (-not [string]::IsNullOrWhiteSpace($token)) {
$guildsListBox.Items.Clear()
# Fetch guilds
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$guildsResponse = $wc.DownloadString("https://discord.com/api/v10/users/@me/guilds")
$guilds = $guildsResponse | ConvertFrom-Json
foreach ($guild in $guilds) {
$guildsListBox.Items.Add("$($guild.name) ($($guild.id))")
}
$tabControl.SelectTab($appTab) # Switch to the app tab
} else {
[System.Windows.Forms.MessageBox]::Show("Please enter a valid Discord Bot Token.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
# Guilds list box selection changed event
$guildsListBox.Add_SelectedIndexChanged({
$channelsListBox.Items.Clear() # Clear previous channels
$usersListBox.Items.Clear() # Clear previous users
$outputBox.Clear()
$token = $tokenTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
if ($selectedGuild) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
# Fetch channels
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$channelsResponse = $wc.DownloadString("https://discord.com/api/v10/guilds/$guildId/channels")
$channels = $channelsResponse | ConvertFrom-Json
foreach ($channel in $channels) {
# Display channel name and ID
if ($channel.type -eq 0) { # Only include text channels
$channelsListBox.Items.Add("$($channel.name) ($($channel.id))")
}
}
# Fetch users (members) of the guild
$membersResponse = $wc.DownloadString("https://discord.com/api/v10/guilds/$guildId/members?limit=1000")
$members = $membersResponse | ConvertFrom-Json
foreach ($member in $members) {
$usersListBox.Items.Add("$($member.user.username) ($($member.user.id))")
}
}
})
$channelsListBox.Add_SelectedIndexChanged({
$outputBox.Clear()
$token = $tokenTextBox.Text
$selectedChannel = $channelsListBox.SelectedItem
if ($selectedChannel) {
$channelId = $selectedChannel -replace '.* \((.*)\)', '$1' # Extract the Channel ID
# Fetch messages
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$messagesResponse = $wc.DownloadString("https://discord.com/api/v10/channels/$channelId/messages")
$messages = $messagesResponse | ConvertFrom-Json
# Reverse the messages order
$messages = $messages | Sort-Object timestamp -Unique
foreach ($message in $messages) {
$username = $message.author.username
$timestamp = [datetime]::Parse($message.timestamp).ToString("yyyy-MM-dd HH:mm:ss")
$outputBox.SelectionColor = [System.Drawing.Color]::Gray
$outputBox.SelectionFont = New-Object System.Drawing.Font("Microsoft Sans Serif", 8)
$outputBox.AppendText("[$timestamp] : $username`r`n")
$outputBox.SelectionColor = [System.Drawing.Color]::White
$outputBox.SelectionFont = New-Object System.Drawing.Font("Microsoft Sans Serif", 11)
$outputBox.AppendText("$($message.content)`r`n`n")
$outputBox.ScrollToCaret()
}
}
})
# Send button click event
$sendButton.Add_Click({
$token = $tokenTextBox.Text
$selectedChannel = $channelsListBox.SelectedItem
if ($selectedChannel) {
$channelId = $selectedChannel -replace '.* \((.*)\)', '$1' # Extract the Channel ID
$messageContent = $messageTextBox.Text
if (-not [string]::IsNullOrWhiteSpace($messageContent)) {
# Send message
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$wc.Headers.Add("Content-Type", "application/json")
$messageBody = @{
content = $messageContent
} | ConvertTo-Json
$wc.UploadString("https://discord.com/api/v10/channels/$channelId/messages", "POST", $messageBody)
$messageTextBox.Clear()
$outputBox.Refresh()
$outputBox.ScrollToCaret()
}
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a channel to send a message.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
# Generate Invite Link button click event
$generateInviteButton.Add_Click({
$token = $tokenTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
$selectedChannel = $channelsListBox.SelectedItem
if ($selectedGuild -and $selectedChannel) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
$channelId = $selectedChannel -replace '.* \((.*)\)', '$1' # Extract the Channel ID
# Generate invite link
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$wc.Headers.Add("Content-Type", "application/json")
$inviteParams = @{
max_age = 3600 # 1 hour expiration
max_uses = 1 # Single use
target_channel_id = $channelId
} | ConvertTo-Json
$inviteResponse = $wc.UploadString("https://discord.com/api/v10/channels/$channelId/invites", "POST", $inviteParams)
$invite = $inviteResponse | ConvertFrom-Json
$inviteLink = "https://discord.gg/$($invite.code)"
$inviteLinkBox.Text = $inviteLink
} else {
[System.Windows.Forms.MessageBox]::Show("Please select both a guild and a channel.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
# Create new channel button click event
$createChannelButton.Add_Click({
$token = $tokenTextBox.Text
$newChannelName = $newChannelNameTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
if ($selectedGuild -and $newChannelName) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
# Create new channel
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$wc.Headers.Add("Content-Type", "application/json")
$body = @{
name = $newChannelName
type = 0 # Text channel
} | ConvertTo-Json
$wc.UploadString("https://discord.com/api/v10/guilds/$guildId/channels", "POST", $body)
[System.Windows.Forms.MessageBox]::Show("Channel '$newChannelName' created successfully.", "Success", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a guild and enter a channel name.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
# Delete selected channel button click event
$deleteChannelButton.Add_Click({
$token = $tokenTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
$selectedChannel = $channelsListBox.SelectedItem
if ($selectedGuild -and $selectedChannel) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
$channelId = $selectedChannel -replace '.* \((.*)\)', '$1' # Extract the Channel ID
# Delete selected channel
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$wc.UploadString("https://discord.com/api/v10/channels/$channelId", "DELETE", "")
[System.Windows.Forms.MessageBox]::Show("Channel '$selectedChannel' deleted successfully.", "Success", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
$channelsListBox.Items.Remove($selectedChannel) # Remove from listbox
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a guild and a channel to delete.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
# Invite User Button Click Event
$inviteuserButton.Add_Click({
$token = $tokenTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
$selectedChannel = $channelsListBox.SelectedItem
$usernameToInvite = $unbanUserTextBox.Text # Assuming $unbanUserTextBox holds the username
if ($selectedGuild -and $selectedChannel -and $usernameToInvite) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
$channelId = $selectedChannel -replace '.* \((.*)\)', '$1' # Extract the Channel ID
# Generate invite link
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$wc.Headers.Add("Content-Type", "application/json")
# Create invite for the selected channel
$inviteParams = @{
max_age = 3600 # 1 hour expiration
max_uses = 1 # Single use invite
target_channel_id = $channelId
} | ConvertTo-Json
try {
$inviteResponse = $wc.UploadString("https://discord.com/api/v10/channels/$channelId/invites", "POST", $inviteParams)
$invite = $inviteResponse | ConvertFrom-Json
$inviteLink = "https://discord.gg/$($invite.code)"
# Display generated invite link in the inviteLinkBox
$inviteLinkBox.Text = $inviteLink
# Notify or use this link to send it to the given username
[System.Windows.Forms.MessageBox]::Show("Invite link generated for $usernameToInvite : $inviteLink", "Success", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
} catch {
[System.Windows.Forms.MessageBox]::Show("Failed to generate invite link.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a guild, a channel, and provide a username to invite.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
$unbanButton.Add_Click({
$token = $tokenTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
$unbanUsername = $unbanUserTextBox.Text
if ($selectedGuild -and $unbanUsername) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
# Fetch all bans to get the user ID for the given username
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$bansResponse = $wc.DownloadString("https://discord.com/api/v10/guilds/$guildId/bans")
$bans = $bansResponse | ConvertFrom-Json
# Find the user in the ban list by username (no discriminator)
$userToUnban = $bans | Where-Object { $_.user.username -eq $unbanUsername }
if ($userToUnban) {
# Unban the user by user ID
$userId = $userToUnban.user.id
$wc.UploadString("https://discord.com/api/v10/guilds/$guildId/bans/$userId", "DELETE", "")
[System.Windows.Forms.MessageBox]::Show("User '$unbanUsername' unbanned successfully.", "Success", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
} else {
[System.Windows.Forms.MessageBox]::Show("User '$unbanUsername' not found in the ban list.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a guild and enter a valid username.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
# Ban button click event
$banButton.Add_Click({
$token = $tokenTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
$selectedUser = $usersListBox.SelectedItem
if ($selectedGuild -and $selectedUser) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
$userId = $selectedUser -replace '.* \((.*)\)', '$1' # Extract the User ID
# Ban the user
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$wc.UploadString("https://discord.com/api/v10/guilds/$guildId/bans/$userId", "PUT", "")
[System.Windows.Forms.MessageBox]::Show("User '$selectedUser' banned successfully.", "Success", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
$usersListBox.Items.Remove($selectedUser) # Remove from listbox
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a guild and a user to ban.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
# Kick button click event
$kickButton.Add_Click({
$token = $tokenTextBox.Text
$selectedGuild = $guildsListBox.SelectedItem
$selectedUser = $usersListBox.SelectedItem
if ($selectedGuild -and $selectedUser) {
$guildId = $selectedGuild -replace '.* \((.*)\)', '$1' # Extract the Guild ID
$userId = $selectedUser -replace '.* \((.*)\)', '$1' # Extract the User ID
# Kick the user
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("Authorization", "Bot $token")
$wc.UploadString("https://discord.com/api/v10/guilds/$guildId/members/$userId", "DELETE", "")
[System.Windows.Forms.MessageBox]::Show("User '$selectedUser' kicked successfully.", "Success", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
$usersListBox.Items.Remove($selectedUser) # Remove from listbox
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a guild and a user to kick.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
})
function HideWindow {
$Async = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
$Type = Add-Type -MemberDefinition $Async -name Win32ShowWindowAsync -namespace Win32Functions -PassThru
$hwnd = (Get-Process -PID $pid).MainWindowHandle
if($hwnd -ne [System.IntPtr]::Zero){
$Type::ShowWindowAsync($hwnd, 0)
}
else{
$Host.UI.RawUI.WindowTitle = 'hideme'
$Proc = (Get-Process | Where-Object { $_.MainWindowTitle -eq 'hideme' })
$hwnd = $Proc.MainWindowHandle
$Type::ShowWindowAsync($hwnd, 0)
}
}
If ($hideconsole -eq 1){
HideWindow
}
# Show the form
[void]$form.ShowDialog()