send method
Future<DmMessage?>
send({
- String? content,
- List<
EmbedBuilder> ? embeds, - ComponentBuilder? components,
- List<
AttachmentBuilder> ? attachments, - bool? tts,
This function sends a DM message to the user that corresponds to the instance of the User.
GuildMember member = guild.members.cache.getOrFail('240561194958716924');
await member.user.send(content: 'Hello World !');
Implementation
Future<DmMessage?> send ({ String? content, List<EmbedBuilder>? embeds, ComponentBuilder? components, List<AttachmentBuilder>? attachments, bool? tts }) async {
MineralClient client = ioc.use<MineralClient>();
DmChannel? channel = client.dmChannels.cache.get(_id);
if (channel == null) {
Response response = await ioc.use<DiscordApiHttpService>().post(url: '/users/@me/channels')
.payload({ 'recipient_id': _id })
.build();
if (response.statusCode == 200) {
channel = DmChannel.fromPayload(jsonDecode(response.body));
client.dmChannels.cache.putIfAbsent(channel.id, () => channel!);
}
}
Response response = await client.sendMessage(channel!,
content: content,
embeds: embeds,
components: components,
attachments: attachments
);
final payload = jsonDecode(response.body);
if (response.statusCode == 200) {
DmMessage message = DmMessage.from(channel: channel, payload: payload);
channel.messages.cache.putIfAbsent(message.id, () => message);
return message;
}
ioc.use<ConsoleService>().warn(payload['message']);
return null;
}