// SendMsg should convert all inputs into a single message. If you supply a object with an ID
// such as a channel, message, role, etc. It will become a reference.  If say the Message provided
// does not have an ID, the Message will populate a CreateMessage with it's fields.
//
// If you want to affect the actual message data besides .Content; provide a
// MessageCreateParams. The reply message will be updated by the last one provided.
SendMsg should convert all inputs into a single message. If you supply a object with an ID
such as a channel, message, role, etc. It will become a reference.  If say the Message provided
does not have an ID, the Message will populate a CreateMessage with it's fields.

If you want to affect the actual message data besides .Content; provide a
MessageCreateParams. The reply message will be updated by the last one provided.
// SendMsg should convert all inputs into a single message . If you supply a object with an ID // such as a channel message role etc . It will become a reference . If say the Message provided // does not have an ID the Message will populate a CreateMessage with it ' s fields . // // If you want to affect the actual message data besides . Content ; provide a // MessageCreateParams . The reply message will be updated by the last one provided .
func (c clientQueryBuilder) SendMsg(channelID Snowflake, data ...interface{}) (msg *Message, err error) {
	var flags []Flag
	params := &CreateMessageParams{}
	addEmbed := func(e *Embed) error {
		if params.Embed != nil {
			return errors.New("can only send one embed")
		}
		params.Embed = e
		return nil
	}
	msgToParams := func(m *Message) (s string, err error) {
		if s, err = m.DiscordURL(); err != nil {
			if len(m.Embeds) > 1 {
				return "", errors.New("can only create a message with a single embed")
			} else if len(m.Embeds) > 0 {
				params.Embed = m.Embeds[0]
			}
			params.Content = m.Content
			params.SpoilerTagAllAttachments = m.SpoilerTagAllAttachments
			params.SpoilerTagContent = m.SpoilerTagContent
			params.Tts = m.Tts
			return "", nil
		}
		return s, nil
	}
	for i := range data {
		if data[i] == nil {
			continue
		}
		var s string
		switch t := data[i].(type) {
		case *CreateMessageParams:
			*params = *t
		case CreateMessageParams:
			*params = t
		case CreateMessageFileParams:
			params.Files = append(params.Files, t)
		case *CreateMessageFileParams:
			params.Files = append(params.Files, *t)
		case Embed:
			if err = addEmbed(&t); err != nil {
				return nil, err
			}
		case *Embed:
			if err = addEmbed(t); err != nil {
				return nil, err
			}
		case *os.File:
			return nil, errors.New("can not handle *os.File, use a CreateMessageFileParams instead")
		case string:
			s = t
		case *Flag:
			flags = append(flags, *t)
		case Flag:
			flags = append(flags, t)
		case Message:
			if s, err = msgToParams(&t); err != nil {
				return nil, err
			}
		case *Message:
			if s, err = msgToParams(t); err != nil {
				return nil, err
			}
		case AllowedMentions:
			params.AllowedMentions = &t
		case *AllowedMentions:
			params.AllowedMentions = t
		default:
			var mentioned bool
			if mentionable, ok := t.(Mentioner); ok {
				if s = mentionable.Mention(); len(s) > 5 {
					mentioned = true
				}
			}
			if !mentioned {
				if str, ok := t.(fmt.Stringer); ok {
					s = str.String()
				} else {
					s = fmt.Sprint(t)
				}
			}
		}
		if s != "" {
			params.Content += " " + s
		}
	}
	if data == nil {
		if mergeFlags(flags).IgnoreEmptyParams() {
			params.Content = ""
		} else {
			return nil, errors.New("params were nil")
		}
	}
	return c.Channel(channelID).WithContext(c.ctx).CreateMessage(params, flags...)
}
func ( c clientQueryBuilder ) SendMsg ( channelID Snowflake , data ... interface { } ) ( msg * Message , err error ) { var flags [ ] Flag params := & CreateMessageParams { } addEmbed := func ( e * Embed ) error { if params . Embed != nil { return errors . New ( " " ) } params . Embed = e return nil } msgToParams := func ( m * Message ) ( s string , err error ) { if s , err = m . DiscordURL ( ) ; err != nil { if len ( m . Embeds ) > 1 { return " " , errors . New ( " " ) } else if len ( m . Embeds ) > 0 { params . Embed = m . Embeds [ 0 ] } params . Content = m . Content params . SpoilerTagAllAttachments = m . SpoilerTagAllAttachments params . SpoilerTagContent = m . SpoilerTagContent params . Tts = m . Tts return " " , nil } return s , nil } for i := range data { if data [ i ] == nil { continue } var s string switch t := data [ i ] . ( type ) { case * CreateMessageParams : * params = * t case CreateMessageParams : * params = t case CreateMessageFileParams : params . Files = append ( params . Files , t ) case * CreateMessageFileParams : params . Files = append ( params . Files , * t ) case Embed : if err = addEmbed ( & t ) ; err != nil { return nil , err } case * Embed : if err = addEmbed ( t ) ; err != nil { return nil , err } case * os . File : return nil , errors . New ( " " ) case string : s = t case * Flag : flags = append ( flags , * t ) case Flag : flags = append ( flags , t ) case Message : if s , err = msgToParams ( & t ) ; err != nil { return nil , err } case * Message : if s , err = msgToParams ( t ) ; err != nil { return nil , err } case AllowedMentions : params . AllowedMentions = & t case * AllowedMentions : params . AllowedMentions = t default : var mentioned bool if mentionable , ok := t . ( Mentioner ) ; ok { if s = mentionable . Mention ( ) ; len ( s ) > 5 { mentioned = true } } if ! mentioned { if str , ok := t . ( fmt . Stringer ) ; ok { s = str . String ( ) } else { s = fmt . Sprint ( t ) } } } if s != " " { params . Content += " " + s } } if data == nil { if mergeFlags ( flags ) . IgnoreEmptyParams ( ) { params . Content = " " } else { return nil , errors . New ( " " ) } } return c . Channel ( channelID ) . WithContext ( c . ctx ) . CreateMessage ( params , flags ... ) }
SendMsg should convert all inputs into a single message.
SendMsg should convert all inputs into a single message .
// try to reference the message, otherwise use it to // populate the params // wtf?