send method
Future<DmMessage?>
send({
- String? content,
- List<
EmbedBuilder> ? embeds, - List<
RowBuilder> ? components, - bool? tts,
Envoie un message en DM à l'utilisateur
Example :
GuildMember? member = guild.members.cache.get('240561194958716924');
await member.user.send(content: 'Hello World !');
Implementation
Future<DmMessage?> send ({ String? content, List<EmbedBuilder>? embeds, List<RowBuilder>? components, bool? tts }) async {
MineralClient client = ioc.use<MineralClient>();
DmChannel? channel = client.dmChannels.cache.get(_id);
/// Get channel if exist or create
if (channel == null) {
Response response = await ioc.use<HttpService>().post(url: '/users/@me/channels', payload: { 'recipient_id': _id });
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
);
if (response.statusCode == 200) {
dynamic payload = jsonDecode(response.body);
DmMessage message = DmMessage.from(channel: channel, payload: payload);
channel.messages.cache.putIfAbsent(message.id, () => message);
return message;
}
return null;
}