reply method
Sends a reply to a Message
At least a message
or one MessageEmbed in embeds
must be provided!
Implementation
Future<void> reply([String? message, List<MessageEmbed>? embeds]) async {
Map<String, dynamic> messageObject = {
"content": message,
"message_reference": {
"message_id": id,
"channel_id": channel.id,
"guild_id": channel.guild?.id,
"fail_if_not_exists": false,
},
"embeds": null
};
if (embeds != null) {
messageObject["embeds"] = generateDiscordEmbedsObject(embeds);
}
http.Response response = await http.post(
Uri.parse("${constants.apiBaseURL}/channels/${channel.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)");
}
}