sendMessage method
Send a message to the TextChannel instance
At least a message
or one MessageEmbed in embeds
must be provided!
Implementation
Future<void> sendMessage(
[String? message, List<MessageEmbed>? embeds]) async {
Map<String, dynamic> messageObject = {
"content": message,
"embeds": null,
};
if (embeds != null) {
messageObject["embeds"] = generateDiscordEmbedsObject(embeds);
}
http.Response response = await http.post(
Uri.parse("${constants.apiBaseURL}/channels/$id/messages"),
headers: {
"Authorization": "Bot ${config.botToken}",
"Content-Type": "application/json",
},
body: jsonEncode(messageObject),
);
if (response.statusCode != 200) {
throw Exception("Failed to send message. ($message)");
}
}