Created
October 1, 2023 09:18
-
-
Save wolfenrain/7bacd65c0c44764c474c34b7e73aa920 to your computer and use it in GitHub Desktop.
Dart code to create an application owned webhook in Discord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'dart:io'; | |
final client = HttpClient(context: SecurityContext(withTrustedRoots: true)); | |
Future<Map<String, dynamic>> createDiscordWebhook({ | |
required String channelId, | |
required String authorization, | |
required String name, | |
}) async { | |
final request = await client.postUrl( | |
Uri.parse('https://discord.com/api/channels/$channelId/webhooks'), | |
) | |
..headers.add('Content-Type', 'application/json') | |
..headers.add('User-Agent', 'DartClient (https://discord.com, 0)') | |
..headers.add('Authorization', 'Bot $authorization') | |
..write(json.encode({'name': name})); | |
final response = await request.close(); | |
return json.decode(utf8.decode(await response.first)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment