MCPcopy Create free account
hub / github.com/Botloader/botloader / discord_create_message

Method discord_create_message

components/runtime/src/extensions/discord.rs:524–597  ·  view source on GitHub ↗
(
        &self,
        args: OpCreateChannelMessage,
    )

Source from the content-addressed store, hash-verified

522 }
523
524 async fn discord_create_message(
525 &self,
526 args: OpCreateChannelMessage,
527 ) -> Result<Message, anyhow::Error> {
528 let rt_ctx = get_rt_ctx(&self.state);
529
530 let channel = parse_get_guild_channel(&self.state, &rt_ctx, &args.channel_id).await?;
531
532 let attachments = convert_attachments(args.fields.attachments.unwrap_or_default())?;
533
534 let maybe_embeds = args
535 .fields
536 .embeds
537 .unwrap_or_default()
538 .into_iter()
539 .map(Into::into)
540 .collect::<Vec<_>>();
541
542 let components = args
543 .fields
544 .components
545 .unwrap_or_default()
546 .into_iter()
547 .map(TryInto::try_into)
548 .collect::<Result<Vec<_>, _>>()?;
549
550 let mentions: Option<twilight_model::channel::message::AllowedMentions> =
551 args.fields.allowed_mentions.map(Into::into);
552
553 discord_request_retry(&self.state, |discord_config| async {
554 let conf = discord_config;
555 let mut mc = conf
556 .client
557 .create_message(channel.id)
558 .embeds(&maybe_embeds);
559
560 if let Some(flags) = &args.fields.flags {
561 mc = mc.flags(flags.clone().into());
562 }
563
564 mc = mc.components(&components);
565
566 if let Some(content) = &args.fields.content {
567 mc = mc.content(content)
568 }
569
570 if mentions.is_some() {
571 mc = mc.allowed_mentions(mentions.as_ref());
572 }
573
574 if let Some(reply) = &args.fields.reply_to_message_id {
575 mc = mc.reply(parse_discord_id(reply)?);
576 }
577
578 if let Some(forward) = &args.fields.forward {
579 // Validate the forwarded message exists in this guild to prevent forwarding what doesn't belong to us
580 let src_channel = parse_get_guild_channel(&self.state, &rt_ctx, &forward.channel_id).await?;
581 mc = mc.forward(

Callers

nothing calls this directly

Calls 6

get_rt_ctxFunction · 0.85
parse_get_guild_channelFunction · 0.85
convert_attachmentsFunction · 0.85
discord_request_retryFunction · 0.85
parse_discord_idFunction · 0.85
forwardMethod · 0.80

Tested by

no test coverage detected